题目:输入几个学生的姓名,性别,年龄,并显示。
程序代码如下,能通过编译但通不能按预想运行。
import javax.swing.JOptionPane;
import java.io.*;
class student
{
String sname,ssex,sage;
}
public class study
{
public static void main(String[] args)
{
student stu[]=new student[3];
for(int i=0;i<3;i++)
{
stu[i].sname=JOptionPane.showInputDialog("Enter the "+i+" student name:");
stu[i].ssex=JOptionPane.showInputDialog("Enter the sex of the student:");
stu[i].sage=JOptionPane.showInputDialog("Enter the age of the student:");
}
for(int i=0;i<3;i++)
{
System.out.println("the"+i+"student name is:"+stu[i].sname);
System.out.println("sex:"+stu[i].ssex);
System.out.println("age:"+stu[i].sage);
}
System.exit(0);
}
}