Advertisement
brilliant_moves

TestRound.java

May 29th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class TestRound {
  4.  
  5.     /**
  6.     *   Program:    TestRound.java
  7.     *   Purpose:    Test cradle for Math.round() on decimal numbers.
  8.     *   Creator:    Chris Clarke, author "50 Java Program Source Codes" and now
  9.     *           "50 More Java Source Codes", both books available now from Amazon.
  10.     *           Practical, working code = homework done in a jiffy!!!
  11.     *   Created:    29.05.2014
  12.     */
  13.  
  14.     public static void main(String[] args) {
  15.  
  16.         Scanner in = new Scanner(System.in);
  17.         double d = 0.0f;
  18.  
  19.         do {
  20.             System.out.print("Enter decimal (like 2.5) to round (negative quits): ");
  21.             d = in.nextDouble();
  22.  
  23.             if (d<0) break; // out of do..while
  24.  
  25.             // round to nearest int
  26.             System.out.println( Math.round(d));
  27.         } while (true);
  28.  
  29.     } // end main()
  30.  
  31. } // end class TestRound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement