Home > Back-end >  5, JAVA data type conversion
5, JAVA data type conversion

Time:09-21

Package Study;

Public class DataType {
Public void test01 () {
//string is converted to digital, how much is the numerical
Char var='A';
System. The out. Println (var);
System. The out. Println (var + 0);
}
Public void test02 () {
//the data type of a small scale automatically converted to a wide range of data types: int, & gt; Float
Float num1=10;//10 is int data, need not cast to float type
System. The out. Println (num1);
}
Public static String getType (Object o) {
//variable types, first to define getType method
Return o.g etClass (). The toString ();
}
Public void test03 () {
//Java string (except char) is one of the biggest, so any type string, are automatically converted to string type
String Str01="" + 10;
String Str02="" + 10.0;
String Str03="" + 'A';
System. The out. Println (getType (Str01));
System. The out. Println (getType (Str02));
System. The out. Println (getType (Str03));
}
Public void test04 () {
//in large range of data types into a range of data types, must cast
Float num1=1534.3 f;
System. The out. Println (num1);
Int num2=(int) num1;
System. The out. Println (num2);
}
Public static void main (String [] args) {

DataType test01=new DataType ();
Test01. Test01 ();
Test01. Test02 ();
Test01. Test03 ();
Test01. Test04 ();
}

}

CodePudding user response:

What is this transfer