如何修复两个不显示输出的类?



我正试图让Team Roster和Coach类显示输出,但当我运行程序时,它不会产生输出。它只产生一流的,但在那之后,没有显示任何输出。

public class Team {
public static void main(String[] args) {
String team_name = "Team Georgia";
System.out.println(team_name);
}
//Team Roster
public class Player {
public void main(String[] args) {
String[] first_name = {"Jack","Dave","Henry","John","David","Bob","Tony","Malcolm","Hiro","Jack","Jesus","Luck","Ben", "Benny", "Caboose", "Michael","Taylor","Mark","Hiroshida","Jack","Patric","Davin"};
String[] last_name = {"Le","lynth","Luther","Kendral","Larry","John","Dave","Grendal","Lee","Lyn","Susan","Solo","Holmes","Stark","Potter","Welma","Han","Smith","Solo","Weasly","Emma","Bones"};
String[] position = {"Front","Front","Front","Front","Side","Side","Side","Back","Back","Side","Front","Front","Front","Front","Side","Side","Side","Back","Back","Side","Mid","Mid"};
for ( int i = 0; i < first_name.length; i++ ) {
//System.out.print("First name: " + first_name[i]+ "tt" + " Last name: " + last_name[i] + "ttt" + " Position: " + position[i] + "n" );
System.out.println("First name: " + first_name[i]);
System.out.println("Last name: " + last_name[i]);
System.out.println("Position: " + position[i]);
}
}   
}

//Coach
public class Coach {
public void main(String[] args) {
String[] first_name = {"Brown","Dave","Jack","King"};
String[] last_name = {"Jun","Jac","Frost","Kong"};
String[] title = {"Head Coach", "Assistant Coach", "Offensive Coordinator", "Defensive Coordinator"};
for ( int i = 0; i < first_name.length; i++ ) {
//System.out.print("First name: " + first_name[i]+ "tt" + " Last name: " + last_name[i] + "ttt" + " Position: " + title[i] + "n" );
System.out.println("First name: " + first_name[i]+ " Last name: " + last_name[i] + " Position: " + title[i]);
}
}
}
}

类Player和Coach是内部类,其中Team是主要的Public类,您的文件也将仅以Team类的名称保存(Team.java(。因此,只有Team类的main((方法被调用,为了运行嵌套类的主要方法,还需要分别对它们进行分类。

由于嵌套类不是静态的,要调用嵌套类的main((方法,首先需要创建Team类的对象,然后引用其他嵌套类对象,并从该对象调用main方法。

例如,

new Team().new Player().main(args);
new Team().new Coach().main(args);

相关内容

  • 没有找到相关文章

最新更新