using java write a program to input any 10 integers and print the largest and second largest number in the given set of integers assume no duplicate no in the set of the number
Answers
HEY MATE!
HERE IS YOUR ANSWER!
I AM ASSUMING THAT YOU KNOW ARRAYS!
import java.util.Scanner;
class program{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n =sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int max1=a[0],max2=a[0];
for(int j=0;j<n;j++){
if(a[j]>max1){
max1=a[j];
}
}
for(int k=0;k<n;k++){
if(a[k]>max2 && max1>a[k]){
max2=a[k];
}
}
System.out.println(max1+" "+max2);
}
}
its an array program!
i have taken the set of no.s from user
its a JAVA PROGRAM DON'T WORRY!!
IT CAN'T BE SOLVED WITHOUT AN ARRAY!!!
HOPE IT HELPS!
PLZ MARK ME AS BRAINLIEST!