Lefty
2010-12-09 18:21:23 UTC
2
3
WHOPPER
CHICKEN SANDWICH
CHICKEN SANDWICH
2
WHOPPER
WHOPPER
2
CHICKEN SANDWICH
WHOPPER
(where the first integer is the number of data sets, the second is the number of food items in the first data set...etc)
and prints the total fat conent for each data set on a separate line?
The output should be...
90g
128g
77g
the fat content of a whopper is 64g, and the sandwich is 13g. Those are my only two values for food.
I am inexperienced in java(obviously) but have been working at this for several hours. This is what I have so far...(please dont laugh, ive never dealt with exceptions or try statements before)
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.IOException;
public class FatCounter
{
public static void main(String[] args)
throws FileNotFoundException, IOException
{
Scanner console = new Scanner(System.in);
FileReader reader = new FileReader("input.txt");
Scanner in = new Scanner(reader);
try
{
int sets = in.nextInt();
int foods = in.nextInt();
while(in.hasNextLine())
{
for (int i = 1; i<=foods;i++)
{
//confused on the loop structure here
}
}
}
finally //not sure what to put here
{
System.exit(0);//?
}
}
}
(sorry about the lack of indentation, its yahoo, not me)