I have an int array tmax[]
, which is defined in my main
method, and an arrayMax
method which is defined within the same class but not the main
function
excerpt from main
:
int maximumTemp = arrayMax(tmax[]);
function arrayMax
:
public static int arrayMax(int[] a) {
int max = a[0];
for (int i = 1; i < a.length; i++)
if (a[i] > max)
max = a[i];
return max;
}
for some reason I get 3 error messages on the line for defining maximumTemp
:
Syntax error, insert ".class" to complete ArgumentList
The method (arrayMax(int[])) in the type Weather //which is my class name// is not applicable for the arguments (Class <tmax[]>)
tmax cannot be resolved to a type
here's the whole code:
import java.io.*;
import java.util.Scanner;
import java.util.regex.Pattern;
public class Weather {
public static void main(String[] args) throws FileNotFoundException {
int a;
File weatherData = new File("C:\\Users\\taddi\\eclipse-workspace\\COS_160_ASSIGNMENT_10\\src\\PortlandWeather1941to2018.txt");
Scanner scnr = new Scanner(weatherData);
scnr.useDelimiter(Pattern.compile("[/\\s]+"));
int totalCount = scnr.nextInt();// this reads the number at the beginning and uses it so I know how many times to run the loop
String throwAway1 = scnr.nextLine();//these statement are used to throw a way the rest of line 1, and all of line 2 and 3
String throwAway2 = scnr.nextLine();
String throwAway3 = scnr.nextLine();
int[] month = new int[totalCount];
int[] day = new int[totalCount];
int[] year = new int[totalCount];
int[] tmax = new int[totalCount];
int[] tmin = new int[totalCount];
System.out.println(totalCount);
for (a = 0; a < totalCount; a ++) {
month[a] = scnr.nextInt();
System.out.print(month[a] + " ");
day[a] = scnr.nextInt();
System.out.print(day[a] + " ");
year[a] = scnr.nextInt();
System.out.print(year[a]);
tmax[a] = scnr.nextInt();
System.out.print(tmax[a]);
tmin[a] = scnr.nextInt();
System.out.println(tmin[a]);
}
int maximumTemp = arrayMax(tmax[]);
}
public static int arrayMax(int[] a) {
int max = a[0];
for (int i = 1; i < a.length; i++)
if (a[i] > max)
max = a[i];
return max;
}
}