Untitled
unknown
plain_text
3 years ago
768 B
17
Indexable
import java.util.Scanner;
public class Histogram
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
int[] nums = new int[101];
//Time to start reading in numbers
System.out.println("Enter numbers between 1 and 100[-1 to quit]: ");
int num = scan.nextInt();
int base10 = 0;
//Here we will make sure that each entered is accounted for in our array
while (num != -1)
{
nums[num]++;
num = scan.nextInt();
}
for (int count = 1; count <=100;count+=10)
{
System.out.print(count + " - " + (base10+=10) + " | " );
for (int index = count ; index<=base10 ; index++)
{
while(nums[index] > 0) {
System.out.print("*");
nums[index]--;
}
}
System.out.println();
}
}
}
Editor is loading...