Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Declaring ints
- int x; // changing int for loop
- // Getting user input
- // Name
- System.out.println("What is the name of your favorite pet?");
- String name=in.next(); // name--> name of pet user entered
- // How many times
- System.out.println("How many times would you like to see the name appear on the screen?");
- int times=in.nextInt(); // times--> amount of times user wants to see name
- // Vertically/Horizontally
- System.out.println("Would you like to see the names:\n1. Once per line\n2. Horizontally");
- int choice=in.nextInt(); // choice --> used for switch statement
- // Switch statement
- switch(choice)
- { // Start of switch
- case 1:
- {
- if(times>0) // test for positive interger
- {
- for(x=0; x<times; x++)
- {
- System.out.println(name);
- } // End of switch
- } // End of if
- else
- {
- System.out.println("Invalid number for name printing, enter a positive interger.");
- }
- } // End of case 1
- case 2:
- {
- if(times>0) // test for positive interger
- {
- for(x=0; x<times; x++)
- {
- System.out.print(name+"\t");
- } // End of switch
- } // End of if
- else
- {
- System.out.println("Invalid number for name printing, enter a positive interger.");
- }
- }
- default:
- {
- System.out.println("Invalid choice, enter one of the following options availible.");
- }
- } // End of switch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement