-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture16Stars.java
More file actions
38 lines (36 loc) · 859 Bytes
/
Lecture16Stars.java
File metadata and controls
38 lines (36 loc) · 859 Bytes
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
import java.util.Scanner;
/**
*
* Lecture 16
* print a number of *
* determined by user input
*
* @author P.M.Campbell
* @version 2020-fall
*
*/
public class Lecture16Stars{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, n2;
System.out.print("how many stars? ");
// implement the algorithm using while
n = in.nextInt();
while (n >= 1) {
System.out.print("*");
n--;
}
// implement the algorithm using for
System.out.print("how many stars? ");
for (int n3 = in.nextInt();n3 >=1;n3--) {
System.out.print("*");
}
// implement the algorithm using for
// initialization outside of the for() statement.
System.out.print("how many stars? ");
n2 = in.nextInt();
for (;n2 >=1;n2--) {
System.out.print("*");
}
}
}