Type detection: Difference between revisions
Content added Content deleted
(Scala solution added) |
(Added Java) |
||
Line 170: | Line 170: | ||
echo 1 |
echo 1 |
||
1</lang> |
1</lang> |
||
== {{header|Java}} == |
|||
{{trans|Kotlin}} |
|||
<lang Java>public class TypeDetection { |
|||
private static void showType(Object a) { |
|||
if (a instanceof Integer) { |
|||
System.out.printf("'%s' is an integer\n", a); |
|||
} else if (a instanceof Double) { |
|||
System.out.printf("'%s' is a double\n", a); |
|||
} else if (a instanceof Character) { |
|||
System.out.printf("'%s' is a character\n", a); |
|||
} else { |
|||
System.out.printf("'%s' is some other type\n", a); |
|||
} |
|||
} |
|||
public static void main(String[] args) { |
|||
showType(5); |
|||
showType(7.5); |
|||
showType('d'); |
|||
showType(true); |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>'5' is an integer |
|||
'7.5' is a double |
|||
'd' is a character |
|||
'true' is some other type</pre> |
|||
== {{header|JavaScript}} == |
== {{header|JavaScript}} == |