Java编写的学生部分个人信息统计程序

import java.io.*;
import java.lang.*;
class Student
{
 public int num;
 public double score;
 public double weight;
 public String name;
 public int age;
}
class paixu
{
 
 
 
 public static void main(String args[])throws IOException
 {
 
   
  Student k;
  int i,j,m,n,p,q;
  
  String str =new String();
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("1:age(z->a)   2:age(a->z)   3:num(z->a)  4:num(a->z) 5:end");
  for(q=0;q<99;q++)
  {        str=br.readLine();
        p=Integer.parseInt(str);
        if(p==1)
        {System.out.print("Please enter the number of student:");
  str=br.readLine();
  n=Integer.parseInt(str);
  Student stu[];
  stu=new Student[n];
  for(i=0;i<n;i++)//输入
  {
   stu[i]=new Student();
      str=br.readLine();
      m=Integer.parseInt(str);
      stu[i].age=m;
  }
  for(j=0;j<n-1;j++)//排序
  {
   for(i=0;i<n-j-1;i++)
   {
    if(stu[i].age<stu[i+1].age)
    {
     k=stu[i];
     stu[i]=stu[i+1];
     stu[i+1]=k;
    }
   }
  }
  System.out.print("the ages are:");//输出
  for(i=0;i<n;i++)
  {
   System.out.print(stu[i].age+" ");
  }
       }

        if(p==2)
        {System.out.print("Please enter the number of student:");
  str=br.readLine();
  n=Integer.parseInt(str);
  Student stu[];
  stu=new Student[n];
  for(i=0;i<n;i++)//输入
  {
   stu[i]=new Student();
      str=br.readLine();
      m=Integer.parseInt(str);
      stu[i].age=m;
  }
  for(j=0;j<n-1;j++)//排序
  {
   for(i=0;i<n-j-1;i++)
   {
    if(stu[i].age>stu[i+1].age)
    {
     k=stu[i];
     stu[i]=stu[i+1];
     stu[i+1]=k;
    }
   }
  }
  System.out.print("the ages are:");//输出
  for(i=0;i<n;i++)
  {
   System.out.print(stu[i].age+" ");
  }}
       if(p==3)
       {
     System.out.print("Please enter the number of student:");
  str=br.readLine();
  n=Integer.parseInt(str);
 Student stu[]=new Student[n];
 for( i = 0;i<n;i++){
    str = br.readLine();
    stu[i] =new Student();
    stu[i].num = Integer.parseInt(str);    
}

 

 Student t = new Student();


  for(i=0;i<n;i++)
   {
      for( j=0;j<n-1-i;j++)
      if(stu[j].num<stu[j+1].num)
       {t=stu[j+1];
        stu[j+1]=stu[j];
        stu[j]=t;}}

for( i=0;i<n;i++)
  System.out.print(stu[i].num+"  ");
}
if(p==4)
       {
     System.out.print("Please enter the number of student:");
  str=br.readLine();
  n=Integer.parseInt(str);
 Student stu[]=new Student[n];
 for( i = 0;i<n;i++){
    str = br.readLine();
    stu[i] =new Student();
    stu[i].num = Integer.parseInt(str);    
}

 

 Student t = new Student();


  for(i=0;i<n;i++)
   {
      for( j=0;j<n-1-i;j++)
      if(stu[j].num>stu[j+1].num)
       {t=stu[j+1];
        stu[j+1]=stu[j];
        stu[j]=t;}}

for( i=0;i<n;i++)
  System.out.print(stu[i].num+"  ");
}
    if(p==5)
   {break;}
}
 } 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值