I understand that this code will not run because i have 2 string and 1 float type in my text file and i am storing them as int's but how do i do this?.. please someone help me this is so frustrating
Here is my .txt file
100
200
bogus
300
150
weasel
400
600
250
3.5
800
50
500
450
600
550
// CS 0401 Fall 2010
// Lab 10
import java.util.*;
import java.io.*;
public class lab10
{
public static void main(String [] args)
{
Scanner inScan;
Scanner fScan = null;
inScan = new Scanner (System.in);
String nextItem;
int nextInt = 0;
int i = 0;
int [] A = new int [5];
boolean check = true;
String textS = " ";
while (check = true){
System.out.println("Please enter the file to read from: ");
String fName = inScan.nextLine();
try {
fScan = new Scanner (new File(fName));
while (fScan.hasNextLine())
{
nextItem = fScan.nextLine();
nextInt = Integer.parseInt(nextItem);
A[i] = nextInt; // array
i++; // increments the counter
}
System.out.println("Here are your " + i + " items:");
for (int j = 0; j < i; j++)
{
System.out.println(A[j] + " ");
}
} catch (FileNotFoundException e) {
System.out.println("Your file is invalid ");
}
}// end while
}
}