When I read a negative value or a value greater than 128 it doesn.t print anthing...it is supposed to print : ""This is an Integer. Value: " + value": I really cant understand
why is not printing that message when I call it..Can anyone help me, please!!
package com.codegym.task.task15.task1519;
import com.sun.xml.internal.ws.util.StringUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/*
Different methods for different types
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s;
Short sh;
Integer inte;
while (true){
s = reader.readLine();
if(s.equals("exit")) break;
Double dou ;
if(isDouble(s) && s.contains(".")) {
dou = Double.parseDouble(s);
print(dou);
}
else if(isShort(s) ){
sh = Short.parseShort(s);
if(sh > 0 && sh < 128)
print(sh);
}
else if (isInteger(s) ) {
inte = Integer.parseInt(s);
if (inte <= 0 )
print(inte);
if(inte >= 128)
print(inte);
}
else {
print(s);
}
}
}
public static boolean isInteger(String in){
try{
Integer.parseInt(in);
return true;
}
catch(Exception e){
return false;
}
}
public static boolean isDouble(String in){
try{
Double.parseDouble(in);
return true;
}
catch(Exception e){
return false;
}
}
public static boolean isShort(String in){
try{
Short.parseShort(in);
return true;
}
catch(Exception e){
return false;
}
}
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);
}
}