由于main方法/java类文件异常而导致我的程序无法运行 [英] My program won't run due to error with the main method/java class file exception

查看:40
本文介绍了由于main方法/java类文件异常而导致我的程序无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出选择排序算法并通过打印每行来理解它,但是当我运行它时,控制台甚至都不会弹出.我知道我的错误与未找到主类异常和主字符串args方法有关系,但是我不知道如何解决该问题以查看输出.

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

        }
    }
}

推荐答案

排序"中的主要功能为空,因此如果您尝试运行该类,它将不会打印任何内容.

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

    }
}
}

创建另一个类,该类将初始化一个Sorting对象类型,并使用该对象来调用该方法.

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

}

输出-

2147483647
2147483647
2147483647
2147483647
2147483647

这篇关于由于main方法/java类文件异常而导致我的程序无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆