0

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; 
    }       
}
Neuron
  • 5,141
  • 5
  • 38
  • 59
AdamT
  • 39
  • 1
  • 5
  • It's not that your code isn't "working" but rather that it doesn't compile, a completely different issue. Please show more of the code and the full error message. – Hovercraft Full Of Eels Dec 12 '21 at 15:29
  • 2
    [Cannot reproduce](https://ideone.com/RoJXMp). – Turing85 Dec 12 '21 at 15:31
  • 1
    Not `int maximumTemp = arrayMax(tmax[]);` but rather `int maximumTemp = arrayMax(tmax);` do you see the difference? You pass in the array variable into the method, without the empty brackets. Your compilation error is a typographical error. – Hovercraft Full Of Eels Dec 12 '21 at 16:13
  • Thank you so much! That fixed it. It's hard to believe I was staring at it the whole time and didn't notice it. – AdamT Dec 12 '21 at 16:19

0 Answers0