

InterviewSolution
Saved Bookmarks
1. |
Write a program to create an array to store 10 integers and print the largest integer andthe smallest integer in that array. |
Answer» Answer: class Max min { public static VOID main(STRING ARGS[ ]) { Scanner sc=new Scanner(System.in); INT i, min,max; int m[ ]=new int [10 ] for(i=0;i<10;i++) { System.out.println("enter the array elements"); m[i]=sc.nextInt(); } max=m[0]; min=m[0]; for(i=0;i<10;i++) { if(m[i]>max) max=m[i]; if(m[i] min=m[i]; } System.out.println("the greater element is"+max); System.out.println("the smallest element is"+min); } } Explanation: |
|