Java 您好,要求以表格格式显示用户输入

Java 您好,要求以表格格式显示用户输入,java,arrays,getter-setter,Java,Arrays,Getter Setter,要求以表格格式显示用户输入的学生详细信息 For example: Enter the number of students 2 Enter the student1 details 28 Science Is the student from same country[Y/N] N Enter the country Australia Enter the Student2 details 29 Commerce Is the Student from same country[Y/N] Y

要求以表格格式显示用户输入的学生详细信息

For example:
Enter the number of students
2
Enter the student1 details
28
Science
Is the student from same country[Y/N]
N
Enter the country
Australia
Enter the Student2 details
29
Commerce
Is the Student from same country[Y/N]
Y
The student details are
Age         Subject     Country        
28          Science    Australia      
29          Commerce     UK
**默认情况下,如果学生来自同一国家,则该值将在“国家”列下打印为“英国”。 我被困在需要在标题(年龄、姓名、国家)下以表格格式显示值以及默认值(本例中为英国)的位置。 我对java非常陌生,无法进一步学习。你的任何帮助都会对我大有裨益。 提前谢谢

我的代码是:

public class StudentTable{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //Port obj = new Port();
        int a,i;
        String b = null;
        System.out.println("Enter the number of students");
        a = sc.nextInt();
        int[] age = new int[a+1];
        String[] name = new String[a+1];
        for(i=1;i<a+1;i++){
            System.out.println("Enter the students "+i+ " details");
            age[i] = sc.nextInt();
            sc.nextLine();
            name[i] = sc.nextLine();
            System.out.println("Is the student from same country[Y/N]");
            b = sc.nextLine();

                if(b=="N"){
                System.out.println("Enter the country");
                String country = sc.next();
                return;
                }
        }
                if(b=="Y");
                String country = "India";
                    System.out.println("The student details are");
                    System.out.format("%-15s%-15s%-15s","Age","name","country");
公共类学生表{
公共静态void main(字符串[]args){
扫描仪sc=新的扫描仪(System.in);
//端口obj=新端口();
int a,i;
字符串b=null;
System.out.println(“输入学生人数”);
a=sc.nextInt();
int[]年龄=新int[a+1];
字符串[]名称=新字符串[a+1];

对于(i=1;i1)。请阅读“==”或“equals”、sysout.printf和干净代码之间的差异

 public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);



    //Port obj = new Port();
    int count, i;
    String b ;

    System.out.println("Enter the number of students");
    count= sc.nextInt();

    int[] age = new int[count];
    String[]  name = new String[count];
    String[] country=new String[count];
    for (i = 0; i < count; i++) {
        System.out.println("Enter the students " + i+1 + " details");
        System.out.println("Your age?");

        age[i] = sc.nextInt();

        sc.nextLine();
        System.out.println("Your name?");

        name[i] = sc.nextLine();
        System.out.println("Is the student from same country[Y/N]");
        b = sc.nextLine();

        // if(b=="N")
        if (b.equals("N")) {
            System.out.println("Enter the country");
             country[i] = sc.next();

        }
        //if(b=="Y")
        if (b.equals("Y")) {
             country[i] = "India";
        }
    }
   String frmt= String.format("%-15s%-15s%-15s","Age","name","country");
    System.out.println("The student details are");
    System.out.println(frmt);
    for( i=0;i<age.length;i++){

        System.out.printf("%d  %15s  %14s",age[i],name[i],country[i]);
        System.out.println();
    }
}

}
publicstaticvoidmain(字符串[]args){
扫描仪sc=新的扫描仪(System.in);
//端口obj=新端口();
int计数,i;
b串;
System.out.println(“输入学生人数”);
计数=sc.nextInt();
int[]年龄=新int[计数];
字符串[]名称=新字符串[计数];
字符串[]国家=新字符串[计数];
对于(i=0;i对于(i=0;iQuestions正在寻求调试帮助(“为什么此代码不工作?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题说明的问题对其他读者没有用处。请参阅:如何创建问题。使用链接改进您的问题-不要通过注释添加更多信息。谢谢!我们不是在这里讨论问题的i don’我不会阅读你的作业,然后消化你所有的代码,看看偏离的地方。你会准确地告诉我们你的问题是什么。嗨,问题是在数据需要以表格格式显示的地方。i don’我会确保提出的问题更准确,并且达到
b==“N”
b==“Y”
将失败。请参阅。谢谢弗拉基米尔。您的建议帮助我消除了疑虑