import java.util.Scanner; /** * counts from 1 to whatever number of words the user enters.. * * @author William McDaniel Albritton */ public class TheCountIncrement { /** * main method starts the program.. * * @param arguments are not used.. */ public static void main(String args[]){ //create variables to store data String what = new String(); String howMany = new String(); Integer max = new Integer(0); Integer counter = new Integer(1); final Integer ZERO = new Integer(0); //create scanner variable for input Scanner input = new Scanner(System.in); //prompt user for input and get input from user System.out.println("I am the Count! And I like to count!"); System.out.print("What shall I count for you? "); what = input.nextLine(); System.out.print("How many " + what + " shall I count for you? "); howMany = input.nextLine(); try{ //convert to integer max = Integer.parseInt(howMany); //error checking if(max < ZERO){ System.out.println("Sorry, I cannot count negative numbers!"); } else if(max.equals(ZERO)){ System.out.println("Sorry, I cannot count nothing!"); } else{ //loop while count is less than, or equal to max while(counter <= max){ //output message System.out.println(counter + " " + what + "! AH AH AH AH AH!"); //increment (add one) to the count counter++; } } } catch(NumberFormatException parameter){ System.out.println("ERROR: Please enter a whole number!"); } }//end of main.. }//end of class..