赞
踩
- package com.zhou.com.zhou;
-
- import java.util.Scanner;
-
- public class Demo {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int[] arr= new int[5];
- int i=0;
- while(i<=4){
- System.out.println("请输入第"+(i+1)+"个同学分数:");
- int a = in.nextInt();
- arr[i] = a;
- i++;
- }
- System.out.println("各位同学的得分是:");
- for(int x:arr){
- System.out.print(x+" ");
- }
- System.out.println();
- int max=arr[0];
- int min=arr[0];
- int sum=0;
- double num=0;
- for(int j=0;j<arr.length;j++){
- if(max<arr[j]){
- max=arr[j];
- }
- if(min>arr[j]){
- min=arr[j];
- }
- sum+=arr[j];
- if(arr[j]>90){
- num++;
- }
- }
- System.out.println("最大分数是:"+max);
- System.out.println("最小分数是:"+min);
- System.out.println("5位同学成绩的和:"+sum);
- System.out.println("5位同学的平均值是:"+(sum/5));
- System.out.println("本班的成材率是是:"+(num/arr.length)*100+"%");
-
-
-
-
-
-
- }
- }
2. 依次从键盘录入数组元素,然后把数组元素逆序输出 (就是把元素对调)
- package com.zhou.com.zhou;
-
- import java.util.Scanner;
-
- public class Demo1 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int[] arr = new int[5];
- int i=0;
- while(i<=4){
- System.out.println("请输入第"+(i+1)+"数组:");
- int sc = in.nextInt();
- arr[i]=sc;
- i++;
- }
- for(int x:arr){
- System.out.print(x+" ");
- }
- System.out.println();
- for(int j=arr.length-1;j>=0;j--){
- System.out.print(" "+arr[j]);
- }
-
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。