.txt file have these values:
10
40
30
5
18
This code is meant to read the numbers in a .txt file, then saves in to an array. Then use a method to find the biggest number and return the value. I'm getting an error when running it. What did I do wrong?
import java.io.File;
import java.util.Scanner;
public class MinOppgave4 {
public static void main(String[]args)throws Exception{
String fileName = "MinOppgave4tekst.txt";
File mineFile = new File(fileName);
Scanner in = new Scanner(mineFile);
int[] num = new int [5];
for(int i=0; i<num.length; i++)
{
num[i]=in.nextInt();
System.out.println(num[i]);
}
System.out.println("The biggest number is: "+GetTheBiggestNum(num));
}
public static int GetTheBiggestNum(int[] num)
{
int biggestNum = 0;
if ((num[0] > num[1]) && (num[0] > num[2]) && (num[0] > num[3]) && (num[0] > num[4]) && (num[0] > num[5]))
{
biggestNum = num[0];
}
else if ((num[1] > num[0]) && (num[1] > num[2]) && (num[1] > num[3]) && (num[1] > num[4]) && (num[1] > num[5]))
{
biggestNum = num[1];
}
else if ((num[2] > num[0]) && (num[2] > num[1]) && (num[2] > num[3]) && (num[2] > num[4]) && (num[2] > num[5]))
{
biggestNum = num[2];
}
else if ((num[3] > num[0]) && (num[3] > num[1]) && (num[3] > num[2]) && (num[3] > num[4]) && (num[3] > num[5]))
{
biggestNum = num[3];
}
else if ((num[4] > num[0]) && (num[4] > num[1]) && (num[4] > num[2]) && (num[4] > num[3]) && (num[4] > num[5]))
{
biggestNum = num[4];
}
else
{
biggestNum = num[5];
}
return biggestNum;
}
}