首页 > 代码库 > 实验任务11

实验任务11

1.现有36名同学5门课程的成绩,见成绩表.xls。请编写程序,按总分排序。

 1 public class Main
 2 {
 3     public static void main(String[] args)
 4     {    int a[][]={{81,100,74,95,83},{80,100,72,87,80},{73,53,66,75,68},{77,94,59,88,61},{77,95,56,78,71},{75,88,52,65,66},{69,97,76,90,67},{77,70,56,55,58},{72,55,52,58,64},{67,95,69,80,73},{64,72,30,74,56},{81,72,59,74,77},{67,79,64,43,59},{63,61,51,58,45},{80,86,64,91,68},{75,90,60,84,71},{74,84,73,87,66},{69,97,47,60,66},{61,86,48,54,58},{73,67,55,66,52},{66,31,32,43,51},{78,82,56,64,65},{64,77,54,45,62},{62,67,47,56,52},{66,53,42,47,50},{56,77,22,61,46},{64,23,37,47,50},{66,62,40,42,51},{61,54,36,41,44},{65,51,63,55,51},{76,69,40,75,68},{72,85,60,54,50},{56,38,45,57,51},{57,53,47,58,44},{68,45,47,54,39}};
 5         String m,s[]={"李曼","戴刘敏","王小秋","张薇","马勋莹","陈思思","代全涓","李佳昱","张雪萍","陈思迪","宋旭丰","李智","黄时伟","李紫贤","张怡璇","代甲龙","毛思媛","马雯雯","刘靖","李舒曼","李越","胡航","刘飞","毕梦媛","杨今圆","唐宏美","王静容","李思璇","月昭菲","温琼芳","李骏","王亚","黄睿","邹其航","唐志旭"};
 6         int b[]=new int[35];
 7         int i,j,sum=0,c=0;
 8  
 9         for(i=0;i<35;i++){
10             for(j=0;j<5;j++){
11                 sum+=a[i][j];
12             }    b[i]=sum;sum=0;
13         }
14         for(i=0;i<34;i++){
15             for(j=0;j<34;j++){
16                 if(b[j]>b[j+1]){
17                     m=s[j+1];
18                     s[j+1]=s[j];
19                     s[j]=m;
20                     c=b[j+1];
21                     b[j+1]=b[j];
22                     b[j]=c;        
23                 }
24             }
25         }    
26         for(i=0;i<35;i++){
27             System.out.println((i+1)+"."+s[i]+":"+b[i]);
28         }
29     }
30 }

 

2.使用arraycopy方法,实现在排好序的数组{83,78,69,60,59,58,43}中插入62,插入后仍然保持排序。

 1 public class Main
 2 {
 3     public static void main(String[] args)
 4     {    int a[]={83,78,69,60,59,58,43};        //插入62
 5         int b[]=new int[8];
 6         int c=62,i;
 7  
 8         System.arraycopy(a,0,b,0,3);
 9         b[3]=c;
10         System.arraycopy(a,3,b,4,4);
11  
12         for(i=0;i<8;i++){
13             System.out.println("b["+i+"]="+b[i]);
14         }
15     }
16 }

 

3.录入教材P94提取出生年月日的程序,并思考:
 (1)substring方法的含义是什么?
   (2)id.substring(6,10)为什么提取的是年份?
4.使用substring,编写程序,随机输入一个姓名,分离出姓和名。(包括中文名和英文名)

 1 import java.util.*;
 2 public class Main
 3 {
 4     @SuppressWarnings("resource")
 5     public static void main(String[] args)
 6     {    int x=0,i,j=0;
 7         for(i=0;i<=j;i++){
 8             j++;
 9         Scanner scan=new Scanner(System.in);
10         String s=scan.nextLine();
11  
12         if(s.indexOf(" ")!=-1){    
13             x=s.indexOf(" ");
14             System.out.println("\nlast name:"+s.substring(0,x));
15             System.out.println("family name:"+s.substring(x+1));
16             System.out.println("--------------");
17         }
18         else{
19             System.out.println("\nlast name:"+s.substring(0,1));
20             System.out.println("family name:"+s.substring(1));
21             System.out.println("--------------");
22         }    
23         }
24     }
25 }

 

实验任务11