My assignment is this:
Design and implement an application that reads a set of values in the range 1 to 100 from the user and then creates a chart showing how often the values appeared.
This is my code so far:
import java.util.*; public class chap6pp4 { //this is just the assignment number in my textbook-- chapter 6 programming project 4 public static void main() { int numbers[] = new int[10]; int appearNum; Scanner scan = new Scanner (System.in); System.out.println("Enter a set of values from 1 to 100: "); appearNum = scan.nextInt(); while (appearNum >= 1 && appearNum <= 100) { numbers[(appearNum--) / 10]++; System.out.println("Enter another number (-1 to quit): "); appearNum = scan.nextInt(); } System.out.println(); for (int i = 0; i < numbers.length; i++) { System.out.print (" " + (i*11) + " - " + (i+1)*10 + "\t| "); for (int j = 0; j < numbers.length; j++) { System.out.print ("*"); } System.out.println (); } } }
So it compiles, but when I try to run the code by putting some numbers in it keeps on asking me to put more numbers in, or press -1 to quit. When I do -1, it shows a full asterisk chart.
This is what it looks like :
Enter a set of values from 1 to 100:
1 2 4 64 33 33 52 74 74 2 44
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
2 2 44 33 33
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
Enter another number (-1 to quit):
-1
0 - 10 | **********
11 - 20 | **********
22 - 30 | **********
33 - 40 | **********
44 - 50 | **********
55 - 60 | **********
66 - 70 | **********
77 - 80 | **********
88 - 90 | **********
99 - 100 | **********
those inputted numbers are mine. This is what I want the chart to look like, but the program isn't running the way it is supposed to and I don't know why.
Any help is much appreciated!