Hello i'm working on this program and at the beginning steps i'm just having an issue with reading data from a .txt file this is what i have so far.
Here is the data file.
200 1000 800 450 845 1200 800 250 400 0 1500 1800 600 500 1000 700 1400 1700 675 400 900
Here is the code
import java.util.*; import java.io.*; public class lab1 { /** * MW 1:30 - 2:50 * This program will read file from data and make 3 arrays that will contain * information about the daily in take of calories for breakfast, lunch and dinner * then compute total calories per day, average consumed each day, average calories * consumed in each of the three meals, the max numbers of calories consumed in any specific * day, and the max number of calories consumed in any one meal of any type. * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { File file = new File ("C:\\Users\\jfangulo\\workspace\\Lab1\\src\\data.txt"); Scanner in = new Scanner (file); int [] breakfast = new int [7]; int [] lunch = new int [7]; int [] dinner = new int [7]; int counter = 0; if (!(file.exists())) System.out.println("No file found"); while (in.hasNext()); { breakfast [counter] = in.nextInt(); lunch [counter] = in.nextInt(); dinner [counter] = in.nextInt(); counter++; } System.out.println(breakfast[0]); System.out.println(lunch[0]); System.out.println(dinner[0]); } }
The code just hangs. i changed the path name to File file = new File ("data.txt");
and that didn't do anything but hang either.
Any help is appreciated Thanks!