-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_ForLoops.java
More file actions
50 lines (39 loc) · 1.64 KB
/
Copy path1_ForLoops.java
File metadata and controls
50 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Name: David Phan
*
* Project/Class Description:
* This program will ask the user to input a integer
* that they want to be multiplied.
*
* Then it will ask the user how many times it should be
* multiplied.
*
* Known bugs: None
*/
import java.util.*;
public class ForLoops {
// This is the scanner, it will view what the user inputs.
private static final Scanner scanner = new Scanner(System.in);
// This is the main method, it will ask the user to input a integer.
// Then that integer will go through a loop.
// Where the user enters how many times it should be multiplied.
public static void main(String[] args) {
// This print method asks the user to enter the integer.
System.out.println("Enter an integer to be multiplied: ");
// This will save that integer in the number variable.
int number = scanner.nextInt();
// This print method will ask the user to enter the loop integer.
System.out.println("Enter the number of times it should be multiplied: ");
// Then it will be stored into the multiplier variable.
int multiplier = scanner.nextInt();
// This will make sure it will skip unwanted characters.
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
// This loop method will use the multiplier the user entered
// And then multiply with the integer entered.
for(int i = 1; i <= multiplier; i++){
// Then it will print out the value.
System.out.println(number + " x " + i + " = " + number * i);
}
scanner.close();
}
}