To Find the Minimum and Maximum out of given numbers.






photocourtesy:softpedia
To Find the Minimum and Maximum out of given numbers.

import java.util.*;
import java.util.Scanner;
//@opensource
public class Main
{

public static void main(String args[])

{
int sum =100000000,sub=-9997;
System.out.print("Enter the number of inputs");
Scanner a=new Scanner(System.in);
int sayo=a.nextInt();

for(int b=0;b<sayo;b++)
{

System.out.println("Enter the num");
int andy= a.nextInt();

if(andy<sum)
{

sum=andy;

}

if(andy>sub)

{

sub=andy;

}
}
System.out.println("The maximum no. is"+sub);
System.out.println("The minimum no. is"+sum);
}
}

Same can be done to find in Array.


Posted by lol ik.


Comments

Popular Posts