public class CastingString
{
public static void main(String[]args)
{
String boolS = "true";
boolean boolB = Boolean.parseBoolean(boolS);
String charS = "Algoritma itu mudah";
char charC = charS.charAt(0);
String strVal = "3";
byte bVal = Byte.parseByte(strVal);
short sVal = Short.parseShort(strVal);
int iVal = Integer.parseInt(strVal);
long lVal = Long.parseLong(strVal);
String floatStr = "3.1428571428571428571428571428571";
float fVal = Float.parseFloat(floatStr);
double dVal = Double.parseDouble(floatStr);
System.out.println("Boolean string value = "+boolS);
System.out.println("Casting to boolean value = "+boolB);
System.out.println();
System.out.println("Character string value = "+charS);
System.out.println("Casting to character value = "+charC);
System.out.println();
System.out.println("Sting value = "+strVal);
System.out.println("Casting to byte value = "+bVal);
System.out.println("Casting to short value = "+sVal);
System.out.println("Casting to int value = "+iVal);
System.out.println("Casting to long value = "+lVal);
System.out.println();
System.out.println("Float string value = "+floatStr);
System.out.println("Casting to float value = "+fVal);
System.out.println("Casting to double value = "+dVal);
}
}
{
public static void main(String[]args)
{
String boolS = "true";
boolean boolB = Boolean.parseBoolean(boolS);
String charS = "Algoritma itu mudah";
char charC = charS.charAt(0);
String strVal = "3";
byte bVal = Byte.parseByte(strVal);
short sVal = Short.parseShort(strVal);
int iVal = Integer.parseInt(strVal);
long lVal = Long.parseLong(strVal);
String floatStr = "3.1428571428571428571428571428571";
float fVal = Float.parseFloat(floatStr);
double dVal = Double.parseDouble(floatStr);
System.out.println("Boolean string value = "+boolS);
System.out.println("Casting to boolean value = "+boolB);
System.out.println();
System.out.println("Character string value = "+charS);
System.out.println("Casting to character value = "+charC);
System.out.println();
System.out.println("Sting value = "+strVal);
System.out.println("Casting to byte value = "+bVal);
System.out.println("Casting to short value = "+sVal);
System.out.println("Casting to int value = "+iVal);
System.out.println("Casting to long value = "+lVal);
System.out.println();
System.out.println("Float string value = "+floatStr);
System.out.println("Casting to float value = "+fVal);
System.out.println("Casting to double value = "+dVal);
}
}
Tidak ada komentar:
Posting Komentar