I need to design a histogram that prints out an "" for certain intergers and the integers need to be read from a text file. I think I got the hole "" thing down, but the file reading isn't working not matter what I try so I could use a little help.
I simply called the file text.txt.
The full description of what I'm working on is:
"Write a Java program to input an unknown number of integers from a text file and produce a histogram, in your solution, print one “” for each number entered (if we were expecting tons of data, one might have used one “” to represent a bunch of values). Use an array to store the frequency counts. You have no need to store the actual data itself."
This is my code:
import java.util.Scanner;
import java.io.*;
public class file
{
public static void main(String [] args) throws IOException
{
final int LIMIT = 9999;
String file;
String num = "*";
int string;
int[]store = new int [LIMIT];
Scanner scan = new Scanner( new File("text.rtf"));
int file1 = file.hasNext();
System.out.println("This program will read out a histogram from a file");
for( string = 0; string < file1.hasNext; string ++)
{
if (9<= string >= 0 )
store[0]++;
else if (19<= string >= 10)
store[1] ++;
else if (29<= string >= 20)
store[2] ++;
else if (39<= string >= 30)
store[3] ++;
else if (49<= string >= 40)
store[4] ++;
else if (59<= string >= 50)
store[5] ++;
else if (69<= string >= 60)
store[6] ++;
else if (79<= string >= 70)
store[7] ++;
else if (89<= string >= 80)
store[8] ++;
else if (99<= string >= 90)
store[9] ++;
file = scan.nextLine();
System.out.println("*");
}
}
}