Following code will find largest numbers out of five numbers
Code:
public class Java2
{
public static void main(String[] nt)
{
int a=7,b=6,c=2,d=3,e=7;
int[] nti=new int[]{a,b,c,d,e};
int[] temp=new int[5];
int max =nti[0];
for(int i=1;i<nti.length;i++)
{
if(max<nti[i])
{
max=nti[i];
}
}
int j=0;
for(int i=0;i<nti.length;i++)
{
if(nti[i]==max)
{
temp[j]=i;
j++;
}
}
if(j==1)
{
System.out.print("Greatest is: ");
}
else
{ System.out.print("Greatest are: ");
}
for(int i=0;i<j;i++)
{
switch(temp[i])
{
case 0:
System.out.print("A ");
break;
case 1:
System.out.print("B ");
break;
case 2:
System.out.print("C ");
break;
case 3:
System.out.print("D ");
break;
case 4:
System.out.print("E ");
break;
}
}
}
}
Code:
public class Java2
{
public static void main(String[] nt)
{
int a=7,b=6,c=2,d=3,e=7;
int[] nti=new int[]{a,b,c,d,e};
int[] temp=new int[5];
int max =nti[0];
for(int i=1;i<nti.length;i++)
{
if(max<nti[i])
{
max=nti[i];
}
}
int j=0;
for(int i=0;i<nti.length;i++)
{
if(nti[i]==max)
{
temp[j]=i;
j++;
}
}
if(j==1)
{
System.out.print("Greatest is: ");
}
else
{ System.out.print("Greatest are: ");
}
for(int i=0;i<j;i++)
{
switch(temp[i])
{
case 0:
System.out.print("A ");
break;
case 1:
System.out.print("B ");
break;
case 2:
System.out.print("C ");
break;
case 3:
System.out.print("D ");
break;
case 4:
System.out.print("E ");
break;
}
}
}
}
Output: