Created
February 28, 2018 16:57
-
-
Save bahodge/97cabb631c770e2065c9956c4ed89719 to your computer and use it in GitHub Desktop.
A loop that builds a table in the console between a low and high user input number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scanner scan = new Scanner(System.in); | |
boolean userCont; | |
String userAns; | |
do { | |
System.out.print("Enter your min value: "); | |
int userLow = scan.nextInt(); | |
System.out.print("Enter your high value: "); | |
int userHigh = scan.nextInt(); | |
System.out.println("number | squared | cubed"); | |
System.out.println("------ | ------- | -----"); | |
for (int i = userLow; i <= userHigh; i++){ | |
System.out.printf("%-7d" + '|' +"%-9d" + '|' + "%d", i, (int)Math.pow(i, 2), (int)Math.pow(i, 3)); | |
System.out.println(); | |
} | |
System.out.print("Would you like to continue? [y/n]"); | |
userAns = scan.next(); | |
userCont = userAns.equalsIgnoreCase("y"); | |
} while (userCont); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment