package en.javarush.task.jdk13.task12.task1205;
/*
But that's how I want it
*/
public class Solution {
private static String UNEXPECTED_TYPE = "I didn't expect this type of number!";
public static void main(String[] args) {
System.out.println(toCustomString((byte) 12));
System.out.println(toCustomString(12));
System.out.println(toCustomString(12.));
System.out.println(toCustomString(12L));
}
public static String toCustomString(Number number) {
Byte newByte;
int newInt;
Double newDouble;
String finalCondition = "I didn't expect this type of number!";
if (number instanceof Byte) {
newByte = (byte) (number / 2);
String finalByte = newByte.toString() + "b" ;
return finalByte; }
else if (number instanceof Integer) {
newInt = (int) number / 3 ;
String finalInt = Integer.toString(newInt);
return finalInt; }
else if (number instanceof Double) {
newDouble = (double) number / 20;
String finalDouble = newDouble.toString();
return finalDouble; }
else return finalCondition;
}
}
package en.javarush.task.jdk13.task12.task1205;
/*
But that's how I want it
*/
public class Solution {
private static String UNEXPECTED_TYPE = "I didn't expect this type of number!";
public static void main(String[] args) {
System.out.println(toCustomString((byte) 12));
System.out.println(toCustomString(12));
System.out.println(toCustomString(12.));
System.out.println(toCustomString(12L));
}
public static String toCustomString(Number number) {
Byte newByte;
int newInt;
Double newDouble;
String finalCondition = "I didn't expect this type of number!";
if (number instanceof Byte) {
newByte = (byte) (number / 2);
String finalByte = newByte.toString() + "b" ;
return finalByte; }
else if (number instanceof Integer) {
newInt = (int) number / 3 ;
String finalInt = Integer.toString(newInt);
return finalInt; }
else if (number instanceof Double) {
newDouble = (double) number / 20;
String finalDouble = newDouble.toString();
return finalDouble; }
else return finalCondition;
}
}