сломал голову уже. Полдня на одной задаче сижу. Вроде довел до "съедобного " вида, а не пускает валидатор... Помогите, люди добрые)))
package com.javarush.task.task15.task1519;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Разные методы для разных типов
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String r = reader.readLine();
Double d;
short sh;
Integer in;
int iwe=0;
for (int i=0; i<r.length();i++){
if (r.charAt(i) == '.') {
iwe++;
}
}/* счетчик */
if (r.equals("exit")) {
return;
} else if (iwe==1) // если счетчик равен 1
{
d = Double.valueOf(r);
print(d);
} else
try {
sh = Short.parseShort(r);
if ((0 < sh) & (sh < 128)) {
print(sh);
} else {
in = (int) sh;
print(in);
}
} catch (Exception x) {
try {
in = Integer.parseInt(r);
print(in);
} catch (Exception st) {
print(r);
}
}
}
}
public static void print(Double value) {
System.out.println("Это тип Double, значение " + value);
}
public static void print(String value) {
System.out.println("Это тип String, значение " + value);
}
public static void print(short value) {
System.out.println("Это тип short, значение " + value);
}
public static void print(Integer value) {
System.out.println("Это тип Integer, значение " + value);
}
}