-
Notifications
You must be signed in to change notification settings - Fork 0
/
Barchart.java
49 lines (35 loc) · 1.77 KB
/
Barchart.java
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
package jrproject3;
/* Jordan Romano - CSIS 212(B01)
The purpose of this program is to chart 5 numbers between 1 and 30 in the form of asterisks */
import java.util.Scanner; // this imports a class Scanner
public class Barchart { //class name
/* this is the method that begins the
execution of the Java application */
public static void main(String[] args) {
// create a Scanner to obtain input from the command window
Scanner input = new Scanner(System.in);
//print name, date and assignment
System.out.println("Jordan Romano - Exercise 4.16 JHTP - CSIS 212(B01) - 2/4/2023");
//asks for user input, a number between 1 and 30
System.out.printf("Enter five numbers between 1 and 30: %n");
/*Unfortunately, I could not get my case and switch statement to work, so I used an array
to store the 5 numbers that the user inputs to finish this project.
New int here is used to define that the array can hold those 5 numbers in memory*/
int array[]= new int[5];
//for loop stating that the counter that takes in 5 number inputs from a user
for (int counter = 0; counter < 5; counter++)
{//end for loop
//the array stores values according to the counter's 5 user inputs
array[counter] = input.nextInt();
}
//for loop that states the counter is defined as 0 and it must be less than 5
for (int counter = 0; counter <= 5; counter++)
{
//for loop the asterisk counter is 0 by default and
for (int stars = 0; stars < array[counter]; stars++)
//print asterisk to chart the number that the user puts in
System.out.print("*");
System.out.println();
}//end for loop
}//end method
}//end class