【发布时间】:2020-05-27 15:00:49
【问题描述】:
我想在 java 的数组中找到第二大的数字。 我绑从这段代码解决问题。
class Example{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
//Random r=new Random();
int max=0;
int secondMax = 0;
for(int i=0; i<10; i++){
System.out.print("Input an integer : ");
int num = input.nextInt();
if (num>max)
{
secondMax=max;
max=num;
}
}
System.out.println("Max number is : "+max);
System.out.println("Second Max number is : "+secondMax);
}
}
【问题讨论】:
-
您有问题吗?
-
这能回答你的问题吗? Finding the second highest number in array
标签: java