Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class p04_Float_or_Integer {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- if (scanner.hasNextInt()) { //Checking if the number is integer
- int numInt = Integer.parseInt(scanner.nextLine());
- System.out.println(numInt);
- } else { //If the number is double, rounding it
- double numDouble = Double.parseDouble(scanner.nextLine());
- System.out.printf("%d", Math.round(numDouble));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement