Skip to main content

java array FileNotFoundException

2 replies [Last post]
Ah2012
Offline
Joined: 2012-12-12

Hello All,
Thank you for reading my post. I jus started this Java class and I am new to the world of Java. I would appreciate all the help I can get. I hope you can help.

import java.io.FileNotFoundException;
import java.util.Scanner;

public class ScoreRange
{
public static void main(String[] args) throws FileNotFoundException
{
int score;
int printRangeLimit;
int[] rangeLimit = {24, 49, 74, 99, 124, 149, 174, 200};
int[] inRange = {0, 0, 0, 0, 0, 0, 0, 0};

//Scanner inFile = new Scanner(new FileReader("scores.txt"));
Scanner inFile = new Scanner("76\n89\n150\n135\n200\n76\n12\n100\n150\n28\n178\n189\n167\n200"
+ "\n175\n150\n87\n99\n129\n149\n176\n200\n87\n35\n157\n189");
while(inFile.hasNext())
{
score = inFile.nextInt();
for(int index = 0; index < rangeLimit.length; index++)
{
if(score < rangeLimit

)
{
inRange
= inRange
+ 1;
}
}
}
printRangeLimit = printArray(rangeLimit, rangeLimit.length);
System.out.println();
printInRange(inRange, inRange.length);
}
public static int printArray(int[] list, int numOfElements)
{
for (int index = 0; index < numOfElements; index++)
{
System.out.println(list
+ " ");
}
return 0;
}
public static int printInRange(int[] list, int numOfElements)
{
for (int index = 0; index < numOfElements; index++)
{
System.out.println(list
+ " ");
}
return 0;
}
}

This is the code:

import java.util.Scanner;
import java.io.FileNotFoundException;

public class ScoreRangeTest
{// Start Class
public static void main(String[] args)throws FileNotFoundException
{// Start main string
int scores;

int[] scoreLimit = {24, 49, 74, 99, 124, 149, 174, 200};
int[] inRange = {0, 0, 0, 0, 0, 0, 0, 0};

Scanner inFile = new Scanner(new FileReader("scores.txt"));

while(inFile.hasNext())
{//Start while
scores = inFile.nextInt();

for(int i = 0; i < scoreLimit.length; i++)
{
if(scores <= scoreLimit[i])
{
inRange[i] = inRange[i] + 1; // counter
break;
}
}
}//end while

for (int i = 0; i < scoreLimit.length; i++)
{// Start for
System.out.println("Scores stored in range " + scoreLimit[i] + " is " + inRange[i]);
System.out.println();
}//End for
}//End main
}// End class

This is the error message:

error: can not find symbol (FileReader)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rwlarsen
Offline
Joined: 2008-03-28

you're referencing FileReader without importing it.

add an import statement for java.io.FileReader

Ah2012
Offline
Joined: 2012-12-12

Now it is saying that system can not find file specified.