Array always adding to 0???
Hi, I'm new to java. Need help.
My array always adds to 0. I need to be able to add numbers and then do some calculations with it. Calculate average, highest and lowest lap etc. However, it always adds to 0.
I have this code so far:
package reversegear;
public class ReverseGear
{
public static void main(String[] args)
{
int lap;
int overall_total = 0;
int LapTimes[];
LapTimes = new int[12];
ConsoleReader console = new ConsoleReader();
for (lap = 1; lap < 11 ; lap = lap + 1) // The outer loop indexes each lap in the array
{
System.out.print("Please enter the lap time for lap " + lap);
LapTimes[lap] = console.readInt();
}
overall_total = overall_total + LapTimes[lap];
System.out.println("The overall average is : " + (LapTimes[lap])); }
}
__________________________________________
I also have this which was provided to me:
package reversegear;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ConsoleReader {
public ConsoleReader()
{
reader = new BufferedReader(new InputStreamReader(System.in));
}
private BufferedReader reader;
public int readInt()
{
String inputString = readLine();
int n = Integer.parseInt(inputString);
return n;
}
public String readLine()
{
String inputLine = "";
try
{
inputLine = reader.readLine();
} catch (IOException e)
{
System.out.println(e);
System.exit(1);
}
return inputLine;
}
}
___________________________________________
Thanks in advanced
p.s. am using eclipse....