My program won't run due to error with the main method/java class file exception

codingxsigh :

I am trying to figure out the selection sort algorithm and understand it by printing out each line, but when I run it, the console won't even pop up. I know my error has to do something with the main class exception not found and the main string args method but I don't know how to fix it to see the output.

package sort;


public class Sorting {
    private int[] a = new int[]{ 11, 9, 17, 5, 12 }; 



    public Sorting(int[]a) {
        this.a = a;
    }
    public static void main(String[] args) {

    }
    public void sortInSpace(int[]a) {
        for(int startOfUnsorted = 0; startOfUnsorted<a.length; startOfUnsorted++) {
            int smallestInUnsorted = Integer.MAX_VALUE;
            System.out.println(smallestInUnsorted);

        }
    }
}
RR_IL :

Your main function in Sorting is empty so it won't print anything if you try to run that class.

public static void main(String[] args) {

}

Instead I would do the following -

public class Sorting {
private int[] a; 

public Sorting(int[]a) {
    this.a = a;
} 
public void sortInSpace(int[]a) {
for(int startOfUnsorted = 0; startOfUnsorted<a.length; startOfUnsorted++) 
{
        int smallestInUnsorted = Integer.MAX_VALUE;
        System.out.println(smallestInUnsorted);

    }
}
}

Create another class which will initiate an object type of Sorting and use the object to call the method.

public static void main(String [] args)
{
       int[] a = new int[]{ 11, 9, 17, 5, 12 }; 
       Sorting sortObj = new Sorting(a);
       sortObj.sortInSpace(a);

}

Output -

2147483647
2147483647
2147483647
2147483647
2147483647

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238537&siteId=1