Advertisement
viraldim

TheSmallestOf3Numbers

May 13th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. /*4.Write a program that finds the smallest of three numbers.*/
  2.  
  3. /*Tests
  4.  5 2 2  0 -2.5 -5 -1.1 -0.5 -0.1
  5. ans: 2 -5 -1.1 */
  6.  
  7. import java.util.Scanner;
  8.  
  9. public class TheSmallestOf3Numbers {
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner input = new Scanner(System.in);
  13.         double a,b,c;
  14.        
  15.         System.out.println("Enter 3 numbers");
  16.         System.out.println("Enter q to Quit");
  17.        
  18.         while(true){
  19.             try {
  20.                 a = input.nextDouble();
  21.                 b = input.nextDouble();
  22.                 c = input.nextDouble();
  23.             } catch (Exception e) {
  24.                 System.out.println("Bye!");
  25.                 break;
  26.             }  
  27.            
  28.             if (Math.min(a, b)<c) {
  29.                 System.out.println(Math.min(a, b));
  30.             }
  31.             else {
  32.                 System.out.println(c);
  33.             }
  34.         }
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement