Advertisement
valerielashvili

Untitled

Jun 11th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p04_Float_or_Integer {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         if (scanner.hasNextInt()) { //Checking if the number is integer
  8.             int numInt = Integer.parseInt(scanner.nextLine());
  9.             System.out.println(numInt);
  10.         } else {                    //If the number is double, rounding it
  11.             double numDouble = Double.parseDouble(scanner.nextLine());
  12.             System.out.printf("%d", Math.round(numDouble));
  13.         }
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement