Code executes okay, just that there's this weird thing where it'll always print an extra empty string after a (Double) Entry.
Help would be appreciated :)
package com.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
/*
Different methods for different types
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()){
if (scanner.hasNextInt()){
int n = scanner.nextInt();
if (n > 0 && n < 128){
print((short)n);
}
else {
print((Integer)n);
}
}
else if (scanner.hasNextDouble()){
Double x = scanner.nextDouble();
print(x);
}
else {
String s = scanner.nextLine();
if (s.equals("exit")){
break;
}
print((String)s);
}
}
scanner.close();
}
public static void print(Double value) {
System.out.println("This is a Double. Value: " + value);
}
public static void print(String value) {
System.out.println("This is a String. Value: " + value);
}
public static void print(short value) {
System.out.println("This is a short. Value: " + value);
}
public static void print(Integer value) {
System.out.println("This is an Integer. Value: " + value);
}
}