Go to Top

Wednesday, 6 April 2011

To find the greatest and smallest of three numbers

Question 5 : Write a program in Java to find the greatest and the smallest number among three numbers given by the user.


Java Program :


public class greatest_of_three
{
 public static void main(int a,int b,int c)
 {
     int d=0;
     int e=0;
     if (a>b && a>c)
     d=a;
     if (b>a && b>c)
     d=b;
     if (c>a && c>b)
     d=c;
     if (a<b && a<c)
     e=a;
     if (b<a && b<c)
     e=b;
     if (c<a && c<b)
     e=c;
     System.out.println("Among the inputs done i.e. "+a+","+b+","+c);
     System.out.println("The greatest number = "+d);
     System.out.println("The smallest number = "+e);
    }
}

Input : 


a=10
b=20
c=30

Output : 


Among the inputs done i.e. 10,20,30
The greatest number = 30
The smallest number = 10

1 comment:

  1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete

ShareThis