Advertisement
dimipan80

The Smallest of 3 Numbers

Aug 17th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. // Write a program that finds the smallest of three numbers.
  2.  
  3. import java.util.Locale;
  4. import java.util.Scanner;
  5.  
  6. public class _04_TheSmallestOf3Numbers {
  7.  
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Locale.setDefault(Locale.ROOT);
  11.         Scanner scan = new Scanner(System.in);
  12.         System.out.print("Enter 3 Real numbers: ");
  13.         double numA = scan.nextDouble();
  14.         double numB = scan.nextDouble();
  15.         double numC = scan.nextDouble();
  16.  
  17.         double smallest = numA;
  18.         if (numB <= numA && numB <= numC) {
  19.             smallest = numB;
  20.         } else if (numC <= numA && numC <= numB) {
  21.             smallest = numC;
  22.         }
  23.  
  24.         System.out.println("The Smallest of these 3 numbers is: " + smallest);
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement