How do I read input that could be an int or a double? [duplicate]
问题 This question already has answers here : How to test if a double is an integer (14 answers) Closed 4 years ago . I'm writing a program in which I need to take input from the keyboard. I need to take a number in, yet I'm not sure if it's an int or a double . Here's the code that I have (for that specific part): import java.io.*; import java.util.*; //... Scanner input = new Scanner(System.in); int choice = input.nextInt(); I know I can get a String and do parseInt() or parseDouble() , but I