Write and test a Java method minimum() that takes array of integers and print the maximum two values in the array
- برمجة جافا
- 2022-04-19
- softwareEngineer
الأجوبة
import java.util.Scanner;
public class HelloWorld
{
public static void main(String[] args) {
int array[]={5,3,10,12,2,11};
minimum(array);
}
public static void minimum(int a[])
{
int max=0,max2=0;
for(int i =0;i<a.length;i++)
{
if(a[i]>max)
{
max2=max;
max=a[i];
}
else if(a[i]>max2)
max2=a[i];
}
System.out.println("the highest number in array is: "+max);
System.out.println("the 2nd highest number is array is "+max2);
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال