0

Preface: Sorry if this question has an easy fix, I am fairly new to learning java.

I am trying to compile this block of code, but keep receiving an error stating "Cannot find Symbol" for my for statement, pointing towards 'imp.length().

    public static void main(String[] args) {
    double[] imp = new double[7];
    Scanner lengths = new Scanner(System.in);
    String input = lengths.nextLine();
    String[] inp = input.split(" ");

    try{
        for(int i = 0; i < imp.length(); i++){
            double len = Double.parseDouble(inp[i]);
            imp[i] = len;
            if(imp[i] < 0){
                System.out.println("Invalid Input.");
                break;
            }
        }
    }

I have rewritten the block of code multiple times to ensure that everything is within the correct scope, but I continue to get the same error.

ter123
  • 21
  • 7

2 Answers2

0

The error is because there is no .length() method of an array, but there is a .length attribute of the array. (No parentheses).

JimN
  • 340
  • 2
  • 10
0

Jut use length, don't use length() ...

for(int i = 0; i < imp.length; i++)

and, if you are using try you must use catch