/* similar with ReadPositive.java, but it keeps track of the number of attempts Laura Toma csci 101 */ public class ReadPositiveCount { public static void main (String args[]) { //set up reading from user ReadStream r = new ReadStream(); int n; //the number from the user int attempts = 0; //how many times the user entered a value //read an integer from user System.out.print("Please enter a positive integer: "); n = r.readInt(); r.readLine(); attempts = attempts + 1; //one more attempt //repeat if necessary while (n < 0) { System.out.print("Sorry, " + n + " is not positive.."); System.out.print("Please enter a positive integer: "); n = r.readInt(); r.readLine(); attempts = attempts + 1; //one more attempt } //note that at this point, n MUST be positive System.out.println("Finally!"); System.out.println("It took you " + attempts + " attempts.."); } //end of main } // end of class