[ Write a program to input 10 number into an integer array and find the position of Largest & Smallest number of an Array.
Program Code :
import java.util.*;
class Max_Min_Position
{
public static void main(String args[])
{
int i,max,min,maxp=0,minp=0;
int n[]=new int[10];
Scanner sc=new Scanner(System.in);
//Accepting 10 Array Element
for (i=0;i<10;i++)
{
System.out.print("Enter the Array Element = ");
n[i]=sc.nextInt();
}
max=n[0];
min=n[0];
//Checking Largest & Smallest Number within Array Element
for (i=0;i<9;i++)
{
if(n[i]>max)
{
max=n[i];
maxp=i;
}
if(n[i]<min)
{
min=n[i];
minp=i;
}
}
System.out.println("Position of Largest Array Element = "+maxp);
System.out.println("Position of Smallest Array Element = "+minp);
}
}
No comments