Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class TestRound {
- /**
- * Program: TestRound.java
- * Purpose: Test cradle for Math.round() on decimal numbers.
- * Creator: Chris Clarke, author "50 Java Program Source Codes" and now
- * "50 More Java Source Codes", both books available now from Amazon.
- * Practical, working code = homework done in a jiffy!!!
- * Created: 29.05.2014
- */
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- double d = 0.0f;
- do {
- System.out.print("Enter decimal (like 2.5) to round (negative quits): ");
- d = in.nextDouble();
- if (d<0) break; // out of do..while
- // round to nearest int
- System.out.println( Math.round(d));
- } while (true);
- } // end main()
- } // end class TestRound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement