Is there other possible structure to implement the same functionality?
Here is my code:
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
while(true){
String s = r.readLine();
if(s.equals("exit")) break;
if(s.contains("."))
{
try{
Double d = Double.parseDouble(s);
print(d);
}
catch(NumberFormatException e){
print(s);
}
}
else{
try{
Integer i = Integer.parseInt(s);
if(i>0 && i<128){
short sh = i.shortValue();
print(sh);
}
else print(i);
}
catch(NumberFormatException e){
print(s);
}
}
}
}
My code works, however, I would like to receive critiques from you guys.
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Cam
7 February 2020, 20:58
Yeah for real! Looks pretty efficient to me!
0
Jason
10 September 2019, 00:29solution
IDK but this was better than what I came up with. This is pretty damn good in my eyes :P
+2