Java most commonly used data types have basic data types, string objects, arrays, basic data types are divided into: numeric (including shaping and floating-point type), character type, Boolean type, the following a simple program to summarize these data types
1 Public classJavadatacreate {2 Public Static voidMain (string[] args) {3 /*define basic Variable type start*/4 //integer variable definition5 intx,y=56;6x=68;7System.out.println ("1. Decimal integer variable x, y values are:" +x+ "" +y);8 //floating-point variable definition9 floata=25.856f;//single-precision floating-point number definition, must be followed by FTen Doubleb=58.378;//double-precision floating-point number definition, can be added after the D can also not add OneSystem.out.println ("2." The value of the floating-point number, a, and a, respectively: "+a+" "+b); A //character-type variable definition - CharC= ' a '; - Chard=98;//you can define any character with a number in a Unicode table theSystem.out.println ("3. Character variable c,d:" +c+ "" +d+ "corresponding Unicode table numbers are:" + (int) c+ "" + (int) d); - //Boolean type variable definition - BooleanE=true, f=false; -System.out.println ("4. Boolean variable e,f:" +e+ "" +f); + /*define basic variable type End*/ - /*Defining Constants*/ + Final Doublepi=3.142; ASystem.out.println ("The value of the constant pi is:" +PI); at //constants can only be assigned once, and are generally named with uppercase - /*string creation and assignment*/ - Charg[]={' y ', ' e ', ' s ', '! '}; -String h=NewString (g); - //Method 1, create a string object from a character array and initialize -String i=NewString ("hello!"); in //Method 2, create a string object directly and initialize it, and Method 1 is equivalent - String J; toj= "Javadata"; + //Method 3, reference string constants to create string variables, they all point to the same memory -System.out.println ("string h:" +h); theSystem.out.println ("String I:" +i); *System.out.println ("String J:" +j); $j= "Javase";Panax NotoginsengSystem.out.println ("These three method-defined string variables can be re-assigned, such as the J-value is:" +j); - /*array Definition and assignment*/ the intk[]; + String l[]; A //declares two arrays, which are shaped and string, but cannot be used directly thek=New int[5]; +L=NewString[8]; - //now that the array is allocated memory space, you can use the $ intm[]=New int[12]; $ //It is now declared that the array is allocated space at the same time that it can be used directly - intn[]=New int[]{1,2,3,4,5}; - into[]={6,7,8,9}; the //This is done in both ways . - //Simple to useWuyi for(x=0;x<5;x++){ the //Cyclic Assignment -k[x]=x; Wu } - for(x=0;x<5;x++){ About //Loop Output $System.out.println (the value of the "+ (x+1) +" element of the array k,n is: "+k[x]+" "+n[x]); - if(x<4){ -System.out.println (the value of the "+ (x+1) +" element of the "array O" is: "+o[x]); - } A } + //Two-dimensional arrays are declared in the same way as one-dimensional arrays the intp[][]={{1,2,3,8},{4,8,9,89},{16,5,23,36}}; - for(x=0;x<p.length;x++){ $ //outer loop for traversing rows the for(y=0;y<p[x].length;y++){ the //Inner loop for traversing all elements of each row theSystem.out.print (p[x][y]+ ""); the } - System.out.println (); in //line Break the } the } About}
These are the most basic in Java, accumulate a bit more, and hope to be able to use later
Summary of the most commonly used variable definitions in Java