Advertisement
tampurus

3 Greatest of two and three number using if else

Apr 2nd, 2022 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. // Q 5,7
  2. public class MyClass {
  3.     public static void main(String[] args) {
  4.         int a = 5, b = 1 , c = 10;
  5.         int max_two,max_three;
  6.         //checking for two
  7.         if (a>b)
  8.             max_two = a;
  9.         else
  10.             max_two = b;
  11.         // checking for three
  12.         if(a>b){
  13.             if(a>c){
  14.                 max_three = a;
  15.             }
  16.             else
  17.                 max_three = c;
  18.         }
  19.         else
  20.             max_three = b;
  21.            
  22.         System.out.println("Greatest of two number is "+max_two);
  23.         System.out.println("Greatest of three number is "+max_three);
  24.     }
  25. }
  26. /*
  27. Greatest of two number is 5
  28. Greatest of three number is 10
  29. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement