公子玖
2019-09-18 17:33
import java.util.Arrays;
import java.util.Scanner;
public class j{
public static void main(String args[]){
int[] score= new int[7];
System.out.println("请输入成绩:");
Scanner input=new Scanner(System.in);
int arrys=input.nextInt();
System.out.println("成绩的前三名:");
j test=new j();
test.chengji(score);
}
public void chengji(int[] score) {
Arrays.sort(score);
int num=0;
for (int i=score.length-1;i>=0;i--){
if (score[i]<0||score[i]>100){
continue;
}
num++;
if(num>3){
break;
}
System.out.println(score);
}
}}
import java.util.Scanner; public class J { public static void main(String args[]) { int[] score = new int[7]; System.out.println("请输入成绩:"); for (int i = 0; i < 7; i++) { Scanner input = new Scanner(System.in); int arrys = input.nextInt(); score[i] = arrys; } System.out.println("成绩的前三名:"); J test = new J(); test.chengji(score); } public void chengji(int[] score) { Arrays.sort(score); int num = 0; for (int i = score.length - 1; i >= 0; i--) { if (score[i] < 0 || score[i] > 100) { continue; } num++; if (num > 3) { break; } System.out.println(score[i]); } } }
类首字母大写(编程规范)
int arrys = input.nextInt();可以得到键盘获取的值,获取后应该赋值给数组的元素
for循环遍历数组数组时,别忘记角标
arrays 没有被用到
Java入门第一季(IDEA工具)升级版
1165171 学习 · 17581 问题
相似问题