Integer condition is not working whenever i enter value greater than 128 or less than 0 , but whenever i enter big value like 1299999 then Integer condition works and it prints that this value is an Integer
package com.codegym.task.task15.task1519;
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 {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String x="";
while(true){
x=reader.readLine();
if(x.equals("exit")){
break;
}
else if(x.contains(".") && isDouble(x) ){
Double d = Double.parseDouble(x);
print(d);
}
else if( isShort(x)){
Short s=Short.parseShort(x);
if(s>0 && s<128){
print(s);
}
}
else if(isInteger(x)){
try {
int q = Integer.parseInt(x);
if (q <= 0 || q >= 128) {
print(q);
}
}catch(Exception e){
e.printStackTrace();
}
}
else{
print(x);
}
}
}
public static boolean isDouble(String a){
try{
Double s=Double.parseDouble(a);
}catch(Exception e){
return false;
}
return true;
}
public static boolean isShort(String s){
try{
Short a=Short.parseShort(s);
}catch(Exception e){
return false;
}
return true;
}
public static boolean isInteger(String s){
try{
Integer i=Integer.parseInt(s);
if(i<=0||i>=128){
return true;
}
}catch(Exception e){
return false;
}
return true;
}
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);
}
}