Yes, here is the finial code:
/*Author: Melawe(Alem)
* Date of completion: 09/Dec/2011
* Code made for: JClass's first assignment, a Java Programming group.
* Link:[url]http://jclass.freeforums.org]Jclass.freeforums.org[/url]
*
*/
public class JavaPrimitivesMel{
/*make a method to display the value of a primitive
* data type, cast it and print its value and the classes full name.
*/
public static void printClassName(Object obj){
System.out.println(obj + " is a " + obj.getClass().getName());
}
public static void main(String[] args){
String convertMe = "Alem";
byte testByte = (byte) convertMe.charAt(0);
short testShort = (short) convertMe.charAt(1);
int testInt = convertMe.charAt(2);
long testLong = convertMe.charAt(3);
double testDouble = convertMe.charAt(2);
float testFloat = convertMe.charAt(1);
char testChar = convertMe.charAt(0);
JavaPrimitivesMel.printClassName(testByte);
JavaPrimitivesMel.printClassName(testShort);
JavaPrimitivesMel.printClassName(testInt);
JavaPrimitivesMel.printClassName(testLong);
JavaPrimitivesMel.printClassName(testDouble);
JavaPrimitivesMel.printClassName(testFloat);
JavaPrimitivesMel.printClassName(testChar);
}
}
[consol]run:
65 is a java.lang.Byte
108 is a java.lang.Short
101 is a java.lang.Integer
109 is a java.lang.Long
101.0 is a java.lang.Double
108.0 is a java.lang.Float
A is a java.lang.Character
BUILD SUCCESSFUL (total time: 2 seconds)[/console]
Thanks all, it is much appreciated!
-Mel