Simple java programme to display the maximum of four numbers

PROGRAM:             

public class Solution {                                                                                                                                                     
public static void main(String[] args) throws Exception {                                                                                                                                                     

System.out.println("Enter four numbers");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in);                                                                                       

int a=Integer.parseInt(br.readLine());                                                                                                   
int b = Integer.parseInt(br.readLine());                                                                                                 
int c = Integer.parseInt(br.readLine());                                                                                                   
int d = Integer.parseInt(br.readLine());                                                                                

if((a>=b)&&(a>=c)&&(a>=d))       

System.out.print(a);  

else if((b>=c)&&(b>=d)&& (b>=a)

 System.out.print(b);

else if((c>=a)&&(c>=b)&&(c>=d))     

System.out.print(c); 

else if((d>=a)&&(d>=c)&&(d>=b)

System.out.print(d);                                                                                            

}

}

OUTPUT:

Enter four numbers

5 6 8 2

8                                                  

 ALTERATION: 

 To display the minimum of four numbers replace all > (greater than symbol) with <(less than symbol

                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 


Comments

Popular posts from this blog

Java Program to create a large array and copy its values equally to two small arrays and display the second array only

Python program to sum up the Salary when the Name and Age matches with subsequent rows.