java 中对象数组的问题
package StudentDemo;import java.util.*;
public class StudentDemo
{
static Graduate G[]=null;
static Student S[]=null;
static Undergraduate Ug[]=null;
public static void main(String args[])
{
String name,sex;
int sno,mathGreade,EnglishGreade,chinaGreade;
Scanner x =new Scanner(System.in);
System.out.println("请输入人数");
int k=x.nextInt();
Undergraduate Ug[] = new Undergraduate[k];
Graduate G[] = new Graduate[k];
Student S[] = new Student[k];
for(int i=0;i<k;i++)
{
Ug[i] = new Undergraduate();
G[i]= new Graduate();
S[i]= new Student();
S[i].set1(name=x.nextLine());
S[i].set2(sex=x.nextLine());
S[i].set3(sno=x.nextInt());
S[i].set4(chinaGreade=x.nextInt());
S[i].set5(mathGreade=x.nextInt());
S[i].set6(EnglishGreade=x.nextInt());
}
for(int i=0;i<k;i++)
{
G[i].judge1(S[i].get4(),S[i].get5(),S[i].get6());
Ug[i].judge(S[i].get4(),S[i].get5(),S[i].get6());
}
}
}
class Student
{
private String name;
private String sex;
private int sno;
private int chinaGreade;
private int mathGreade;
private int EnglishGreade;
public void set1 (String name)
{
this.name = name;
}
public void set2(String sex)
{
this.sex = sex;
}
public void set3(int sno)
{
this.sno = sno;
}
public void set4(int chinaGreade)
{
this.chinaGreade = chinaGreade;
}
public void set5(int mathGreade)
{
this.mathGreade = mathGreade;
}
public void set6(int EnglishGreade)
{
this.EnglishGreade = EnglishGreade;
}
public String get1()
{
return name;
}
public String get2()
{
return sex;
}
public int get3()
{
return sno;
}
public int get4()
{
return chinaGreade;
}
public int get5()
{
return mathGreade;
}
public int get6()
{
return EnglishGreade;
}
}
class Undergraduate extends Student
{
public void judge(int a,int b,int c)
{
if((a+b+c)/3>60)
System.out.println("jege");
}
}
class Graduate extends Student
{
public void judge1(int a,int b,int c)
{
if((a+b+c)/3>60)
System.out.println("Graduge_jege");
}
}
出现的异常:
请输入人数
1
g
b
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at StudentDemo.StudentDemo.main(StudentDemo.java:32)
求指点