Understanding How to Begin the Java Method

Asked 2 years ago, Updated 2 years ago, 47 views

I finished writing the following code, but I get the error Illegal start of expression for which method.I tried setting the method to Public and changing the Void, but I don't know why.Please explain.

class Assignment2_1 {

    public static void println(int[] seq){
        System.out.println(seq[0]+"+seq[1]+"\n");
    }

    static void swap (int[] seq){
        int temp = seq[0];
        seq[0] = seq[1];
        seq[1] = temp;


    public static int[] copy(int[] seq){
        int n = seq.length;
        int[] result=new int[n];
        for (inti=0; i<n;i++)
        result[i] = seq[i];
        return result;
    }

java

2022-09-29 21:46

1 Answers

There are not enough closed brackets.

class Assignment2_1 {
  public static void println(int[] seq){
    System.out.println(seq[0]+"+seq[1]+"\n");
  }

  static void swap (int[] seq){
    int temp = seq[0];
    seq[0] = seq[1];
    seq[1] = temp;
  } // Here

  public static int[] copy(int[] seq){
    int n = seq.length;
    int[] result=new int[n];
    for (inti=0; i<n;i++)
    result[i] = seq[i];
    return result;
  }
} // Here

and close parentheses to allow compilation.


2022-09-29 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.