Created
March 23, 2015 19:39
-
-
Save khatchad/d2b3fc47587c272e87c1 to your computer and use it in GitHub Desktop.
This program demonstrates a user controlled for loop.
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
import java.util.Scanner; // Needed for the Scanner class | |
/** | |
This program demonstrates a user controlled for loop. | |
*/ | |
public class UserSquares | |
{ | |
public static void main(String[] args) | |
{ | |
int number; // Loop control variable | |
int maxValue; // Maximum value to display | |
System.out.println("I will display a table of " + | |
"numbers and their squares."); | |
// Create a Scanner object for keyboard input. | |
Scanner keyboard = new Scanner(System.in); | |
// Get the maximum value to display. | |
System.out.print("How high should I go? "); | |
maxValue = keyboard.nextInt(); | |
// Display the table. | |
System.out.println("Number Number Squared"); | |
System.out.println("-----------------------"); | |
for (number = 1; number <= maxValue; number++) | |
{ | |
System.out.println(number + "\t\t" + | |
number * number); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment