Error: error: class, interface, or enum expected

0

Why my code is giving the error:

  

error: class, interface, or enum expected

Follow the code:

import java.util.Scanner;

    public class teste175 {

        public static void main (String[] args) {

            Scanner sc = new Scanner (System.in);

            int a, i;
            a = sc.nextInt();

            int v[] = new int [a];

            for (i=0; i<a; i++) {
                v[i] = sc.nextInt();
            }
            funcao (v, a);
        }
    }

    static int funcao (int v[], int a){

        int temp, j, i;

        for (j=0; j<a; j++){
            for (i=1; i<a; i++){

                if (v[i]<v[i-1] {
                    temp = v[i];
                    v[i] = v[i-1];
                    v[i-1] = temp;
                }
            }
        }
        return v;
    }
}
    
asked by anonymous 09.11.2016 / 00:01

1 answer

2

One of the main reasons for you to always be in trouble to understand what is happening in the code is the lack of organization of them. Looking at this code really is very difficult to find a mistake there, even for well experienced programmers. Organizing it is very easy to find all the errors present in the code, not just the reported. This is true for all your code, in Java, C ++ or another language.

The function is out of class, missing parentheses, has wrong return, just to name a few problems. This is much simpler and easier to read:

import java.util.Scanner;

class HelloWorld {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] v = new int[a];
        for (int i = 0; i < a; i++) {
            v[i] = sc.nextInt();
        }
        funcao(v);
        for (int i = 0; i < a; i++) {
            System.out.println(v[i]);
        }
    }

    static void funcao(int[] v) {
        for (int j = 1; j < v.length; j++) {
            for (int i = 1; i < v.length; i++) {
                if (v[i] < v[i - 1]) {
                    int temp = v[i];
                    v[i] = v[i - 1];
                    v[i - 1] = temp;
                }
            }
        }
    }
}

See running on ideone and on CodingGround .

I will not even merit the algorithm being good or bad, I do not know the goal.

    
09.11.2016 / 00:15