//键盘录入多个数据在控制台输出最大值;
// 以0结束
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
while(true){
System.out.println("请输入一个数字");
int s=sc.nextInt();
if(s==0){
break;
}else{
list.add(s);
}
}
mechod(list);
}
public static void mechod(ArrayList<Integer> list) {
Integer [] i= new Integer [list.size()];
list.toArray(i);
Arrays.sort(i);
System.out.println("最大值是"+i[i.length-1]);
} |
|