Java base for constant type conversion

verejava

  • java
  • string

Abstract: http://www.verejava.com/?id=16992572054911 /* Type conversion is divided into the following cases 1. Public class TypeConvert {public class TypeConvert {public static v…

www.verejava.com/?id=1699257…

/* Type conversion is divided into the following types: 1. Integer type conversion 2. Floating point type conversion 3. Public class TypeConvert {public static void main(String[] args) {byte a1=1; */ public class TypeConvert {public static void main(String[] args) {byte a1=1; int b1=2; B1 =a1; b1=a1; System.out.println(b1); byte a2=1; int b2=2; int b3=128; // Converting a large integer type to a small integer type requires a cast and may result in a loss of precision. A2 =(byte)b2; a2=(byte)b3; System.out.println(a2); byte c1=1; Float c2 = 10.3 f; C2 =c1; System.out.println(c2); byte d1=1; Float d2 = 10.3 f; Float d3 = 128.2 f; // Float type to integer without decimal part, requires casting, and may lose precision d1=(byte)d2; d1=(byte)d3; System.out.println(d1); // Boolean types cannot be converted to other types, nor can other types be converted to Boolean types. //e1=(boolean)1; char f1='a'; int f2=1; char f3='b'; int f4='b'+1; char f5='b'+1; F1 =(char)f2; // Int can be converted to a character type. f2=f3; System.out.println(f1); System.out.println(f2); System.out.println(f4); System.out.println(f5); // String concatenation + conversion String STR ="hello"; String str2=str+1; String str3 = STR + 2.5; String str4=str+true; String str5=str+'F'; Println (str2); // String is added to other basic types, which are automatically converted to strings. System.out.println(str3); System.out.println(str4); System.out.println(str5); Byte <short<int<float<long<double 2. By default, integers are int and floating-point types are double */Copy the code

www.verejava.com/?id=1699257…

Use the cloud habitat community APP, comfortable ~

For details, please click
Comments (0)

To:


Related articles

  • Java Basics 003-Java Syntax
  • Java Basics (Data types, operators)
  • Variables and basic data types that are the basis of JAVA syntax
  • 01 – JavaSE basics and Object orientation
  • Java Basics -02 Summary of Keywords, Identifiers, Comments, Constants, changes…
  • Basic Java Syntax —- Keywords, identifiers, constants, and variables
  • JAVA basic syntax (variables, constants, data classes…
  • Java Basic Learning _ Basic Syntax (I) 01_DAY02 Summary
  • Super detailed Summary of Java interview questions (I) Java basics
  • Java basic knowledge Enum full contact

The net friend comment on