Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Reply

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();
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...