1) integer
public class Convert{
public static void main(String[] args){
System.out.println("****Conversion of Int to Integer****");
int i=10;
Integer z= Integer.valueOf(i);
System.out.println("Value of z="+i);
System.out.println("****Conversion of Integer to String****");
String s;
s= Integer.toBinaryString(12);
System.out.println("Value of s is "+s);
System.out.println("****Conversion of Integer to Int****");
Integer y= new Integer(12);
int x= y.intValue();
System.out.println("Value of x"+x);
System.out.println("****Conversion of String to Int****");
double a= Double.parseDouble("123.123");
int k=(int)a;
System.out.println("Value of k="+k);
System.out.println("****Conversion of String to Integer****");
short v= Short.parseShort("10011",2);
Integer b= new Integer(v);
System.out.println("Value of b="+b);
System.out.println("****Conversion of Int to String****");
int e=10;
Integer g= new Integer(e);
String f= Integer.toString(213);
System.out.println("Value of f is "+f);
}
}
2)float
public class Conversion{
public static void main(String[] args){
System.out.println("****Conversion of Float to float****");
float f= new Float("123.23");
System.out.println("Value of f="+f);
System.out.println("****Conversion of Float to String****");
Float g= new Float(123.123);
String y= String.valueOf(g);
System.out.println("Value of y is "+y);
System.out.println("****Conversion of String to Float****");
Float k= Float.valueOf("170.78");
System.out.println("Value of k="+k);
System.out.println("****Conversion of String to float****");
float z= Float.parseFloat("71.11");
System.out.println("Value of z="+z);
System.out.println("****Conversion of float to Float****");
float a=122.24f;
Float x= Float.valueOf(a);
System.out.println("Value of x"+x);
System.out.println("****Conversion of float to String****");
float h=18.45f;
String s= String.valueOf(h);
System.out.println("Value of s is "+s);
}
}
No comments:
Post a Comment