java在控制台循环输入5个数,并输出数组结果,计算这5个数的总分,平均分,最值数组元素按从小到大排序
2个回答
展开全部
package date;
import java.util.Scanner;
import java.util.Arrays;
public class TestScanIn {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int[] nums = new int[5];
int sum = 0;
for(int i = 0; i < 5; i++){
nums[i] = sc.nextInt();
sum += nums[i];
}
System.out.println("总分:" + sum);
System.out.println("平局分:" + sum/5);
swap(nums);
for(int i = 0; i < nums.length; i++){
System.out.print(nums[i] + "\t");
}
}
public static void swap(int[] nums){
Arrays.sort(nums);
}
}
请采纳
import java.util.Scanner;
import java.util.Arrays;
public class TestScanIn {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int[] nums = new int[5];
int sum = 0;
for(int i = 0; i < 5; i++){
nums[i] = sc.nextInt();
sum += nums[i];
}
System.out.println("总分:" + sum);
System.out.println("平局分:" + sum/5);
swap(nums);
for(int i = 0; i < nums.length; i++){
System.out.print(nums[i] + "\t");
}
}
public static void swap(int[] nums){
Arrays.sort(nums);
}
}
请采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询