This is a JAVA PROGRAM THAT NEEDS TO BE WRITTEN Design and implement an applicat
ID: 3793638 • Letter: T
Question
This is a JAVA PROGRAM THAT NEEDS TO BE WRITTEN
Design and implement an application that reads integer values in the range of 1 to 100 from the user and then creates the chart showing how often the values appeared. The chart should look similar to the one shown below. It shows how many values fell in the range from 1 to 10, 11 to 20, and so on. Print an asterisk for every five values in each category. For example, if a category had 17 values, print three asterisks in that row. If a category had 4 values, do not print any asterisks in that row. Be sure to include two classes StarTable and StarTablePrgm. Feel free to make the input/output more user friendly.
Explanation / Answer
import java.util.Scanner;
public class C6pt
{ public static void main(String[] args)
{ int[] counts = new int[10];
Scanner in = new Scanner(System.in);
while(in.hasNextInt())
{
int n = in.nextInt();
if (n < 1 || n > 100)
break;
counts[(n - 1) / 10]++;
}
for (int i = 0; i < 10; i++)
{
System.out.format("%2d-%3d ", i*10+1, i*10+10);
for (int j = 0; j < counts[i]; j++)
System.out.print("*");
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.