Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
991 views
in Technique[技术] by (71.8m points)

intellij idea - Java beginner; errors after copying simple sample code? Is my configuration messed up?

I am one week into learning Java. Suddenly, I have a problem with red squigglies on the line where function that tell me that a ; semicolon or parentheses ) is expected. All my searching has led nowhere, maybe it's a missing import or a setting in my configuration that is not correct.

I am copying the code from this tutorial, at least I believe I have copied it correctly. All works fine until trying to put this function in. What am I doing wrong?

YouTube Tutorial that I am using...please watch

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> numbers = new ArrayList<>();
        for (int i = 1; i < 11; ++i)
            numbers.add(i);
        display(numbers);

        // the next line has errors of ';' expected & ')' expected.
        static void display(ArrayList arr){
            for (int i = 0; i < arr.size(); i++)
                System.out.println(arr.get(i) + " ");
            System.out.println();
        }
    }


question from:https://stackoverflow.com/questions/65713225/java-beginner-errors-after-copying-simple-sample-code-is-my-configuration-mess

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're missing a bracket at the end of the function

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> numbers = new ArrayList<>();
        for (int i = 1; i < 11; ++i)
            numbers.add(i);
        display(numbers);
    } // this bracket

    public static void display(ArrayList arr){
        for (int i = 0; i < arr.size(); i++)
            System.out.println(arr.get(i) + " ");
        System.out.println();
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...