Hi, Does someone see an error in my algorithm ?
To me it seems good and working but can't pass tests.
package fr.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/*
Différentes méthodes pour différents types
*/
public class Solution {
public static void main(String[] args) throws IOException {
//écris ton code ici
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String word;
int number;
boolean isString = false;
while (true) {
word = reader.readLine();
if (word.equals("quitter")) break;
else{
if (isDouble(word)){
Double numberDouble = Double.parseDouble(word);
print(numberDouble);
}
else{
try {
number = Integer.parseInt(word);
if (isShort(number)){
Short numberShort = (short) number;
print(numberShort);
}
else if (isInteger(number)){
print((Integer) number);
}
}
catch (NumberFormatException e){
print(word);
}
}
}
}
}
public static boolean isInteger(int number){
boolean isInteger = false;
if (number <= 0 || number >= 128){
isInteger = true;
}
return isInteger;
}
public static boolean isShort(int number){
boolean isShort = false;
if (number > 0 && number < 128){
isShort = true;
}
return isShort;
}
public static boolean isDouble(String word){
boolean isDouble = false;
for (int i=0 ; i < word.length()-1 ; i++){
if (word.charAt(i) == '.'){
isDouble = true;
//
}
}
return isDouble;
}
public static void print(Double value) {
System.out.println("C'est un Double. Valeur : " + value);
}
public static void print(String value) {
System.out.println("C'est un String. Valeur : " + value);
}
public static void print(short value) {
System.out.println("C'est un short. Valeur : " + value);
}
public static void print(Integer value) {
System.out.println("C'est un Integer. Valeur : " + value);
}
}