A common method of java data type conversion

 

{class Testfun public 

	public static void main (String [] args) { 
		// (a) Cross-type conversion of the parent class Number 
		// 1, str = turn int> the Integer.parseInt (S1) 
		String S1 = ". 19"; 
		int i2 = Integer.parseInt (s1); // str digital conversion for the subject int 
		System.out.println ( "I2 = ++" + (++ I2)); 

		// 2, int turn str => Integer.toString (I3) 
		int I3 = 27; 
		String Integer.toString S4 = (I3); 
		System.out.println ( "S4 =" + S4); 

		//. 3, the floating-point switch = int> (int) d5 of 
		Double = 21.6 d5 of ; 
		int I6 = (int) d5 of; 
		System.out.println ( "I6 =" + I6); 

		//. 4, int turn floating point => (Double) i7 
		int i7 = 60; 
		Double D8 = (Double) i7; 
		System.out.println ( "d8 =" + d8 );
 );
		// (ii) with the parent Number casts
		System.out.println();
		I9 = new new Integer Integer ( ". 17"); 
		System.out.println (i9.intValue ()); // Digital Switch str = int> i9.intValue () 
		System.out.println (i9.shortValue ()) ; // digital Switch str = Short> i9.shortValue () 
		System.out.println (i9.byteValue ()); // digital Switch str = byte> i9.byteValue () 

		System.out.println (); 
		// int turn str (hexadecimal form of different STR) 
		System.out.println (Integer.toString (456)); // Get decimal STR 
		System.out.println (Integer.toBinaryString (456)); // obtaining binary STR 
		System.out.println (Integer.toHexString (456)); // Get hexadecimal STR 
		System.out.println (Integer.toOctalString (456)); // Get octal STR 

	} 

}

  

Guess you like

Origin www.cnblogs.com/andy9468/p/11081993.html