Created
March 19, 2017 13:08
-
-
Save fermopili/e2c5801d65f63b55bf804cedc8501d4d to your computer and use it in GitHub Desktop.
com.javarush.task.task15.task1519
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Разные методы для разных типов | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
while (true) | |
{ | |
String key = reader.readLine(); | |
if ("exit".equals(key)) | |
break; | |
if (key.contains(".")) | |
{ | |
try | |
{ | |
Double d = Double.valueOf(key); | |
print(d); | |
} | |
catch (NumberFormatException e) | |
{ | |
print(key); | |
} | |
continue; | |
} | |
try | |
{ | |
int i = Integer.valueOf(key); | |
if ((i<=0)||(i >=128)) | |
{ | |
print(i); | |
continue; | |
} | |
short s = Short.valueOf(key); | |
if ((s > 0) && (s < 128)) | |
print(s); | |
} | |
catch (NumberFormatException e) | |
{ | |
print(key); | |
} | |
} | |
reader.close(); | |
} | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment