JAVA-1.5-上机
/*1.有10个评委打分,(去掉一个最高一个最低)求平均分。 */ package study; import java.util.*; public class homework { public static void main(String[] args) { Scanner input=new Scanner(System.in); double []g=new double[10]; double max=0,min=0,s=0; System.out.println("请评委输入分数:"); for (int i = 0; i < 10; i++) { g[i]=input.nextDouble(); } for (int i = 0; i < g.length; i++) { if(g[i]>max) { max=g[i]; }else { min=g[i]; } s+=g[i]; } System.out.println("去掉一个最高分一个最低分最后得分:"+String.format("%.2f", (s-max-min)/8.0)); } }
/*2.自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出。 */ package study; import java.util.*; public class homework { public static void main(String[] args) { Random r=new Random(); int []a=new int[10]; int t=0; for (int i = 0; i < a.length; i++) { a[i]=r.nextInt(100); } for (int i = 0; i < a.length-1; i++) { for (int j = 0; j < a.length-1-i; j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); } }
/*3.制作彩票35选7程序。 (就是1~35随机生成7个不重复的数) */ package study; import java.util.*; public class homework { public static void main(String[] args) { Random r=new Random(); int []a=new int[10]; int t=0; for (int i = 0; i < a.length; i++) { a[i]=r.nextInt(35); } for (int i = 0; i < a.length-1; i++) { for (int j = 0; j < a.length-1-i; j++) { if(a[j]==a[j+1]) { a[j+1]++; } } } for (int i = 0; i < 7; i++) { System.out.print(a[i]+" "); } }
/*4.定义一个长度为10的int数组,统计数组中的最大值、最小值、以及奇数和偶数的个数 */ package study; import java.util.*; public class homework { public static void main(String[] args) { Random r=new Random(); int []a=new int[10]; int t=0; int o=0,g=0; for (int i = 0; i < a.length; i++) { a[i]=r.nextInt(100); } for (int i = 0; i < a.length-1; i++) { for (int j = 0; j < a.length-1-i; j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for (int i = 0; i < a.length; i++) { if(a[i]%2==0) { o++; }else if(a[i]%3==0) { g++; } System.out.print(a[i]+" "); } System.out.println("最大值:"+a[9]); System.out.println("最小值:"+a[0]); System.out.println("奇数的个数:"+g); System.out.println("偶数的个数:"+o); } }