编写⼀个JavaApplication程序,要求在控制台上输⼊学⽣学号,可输出该学⽣的姓名。。。
class Student
{
int num;
String name;
double math,chinese,english;
int paiming;
public void setStudent(int s,String a,double b,double c,double d,int e)
{
num=s;name=a;math=b;chinese=c;english=d;paiming=e;
}
public boolean search(int s)
{
if(s==num)
{
return true;
}
else
return false;
}
public String toString()
{
String str="";
str+="姓名:"+name+"\n";
str+="数学:"+math+"\n";
str+="语⽂:"+chinese+"\n";
str+="外语:"+english+"\n";
str+="排名:"+paiming+"\n";
return str;
}
public void disp()
{
System.out.print(toString());
}
public static void main(String[] args)
{
int num1=Integer.valueOf(args[0]).intValue();
Student s1=new Student(),s2=new Student(),s3=new Student(),s4=new Student(), s5=new Student();
s1.setStudent(20201001,"⼩明",100,100,100,1);
s2.setStudent(20201002,"⼩王",90,90,90,2);
s3.setStudent(20201003,"⼩张",80,80,80,3);
s4.setStudent(20201004,"⼩红",70,70,70,4);
s5.setStudent(20201005,"⼩绿",60,60,60,5);
if(s1.search(num1))
{
s1.disp();
}
java怎么编写if(s2.search(num1))
{
s2.disp();
}
if(s3.search(num1))
{
s3.disp();
}
if(s4.search(num1))
{
s4.disp();
}
if(s5.search(num1)) {
s5.disp();
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论