Java data Types : A total of 11 data types, based on how they are used, are divided into basic types and reference types. Basic types: Byte (1 bytes), short (2 bytes), int (4 bytes), Long (8 bytes), Float (4 bytes), double (8 bytes), char (2 bytes), Boolean (indeterminate, determined by the JVM), where Byte, short , int, long is integer, float, double is floating point, char is character, Boolean is Boolean type
Reference type: Class, Interface (interface), array
variables : Used to store data types, variables must be declared before they are used. A variable is a small area of memory that is accessed by using variable names in the program, and each variable must be declared before it is used (that is, requesting a memory area from the JVM) and then assigned (populating the contents of the request area) before the variable is used. Variable declaration such as: int age; float result;
Tips: In Java, you can assign only a value to a variable that strictly matches its data type, unless you use the cast operator.
Here are the code for the 1-100 and the class exercises.
1 //ask for 1-100 and2 Public classSum {3 Public Static voidmain (String [] args) {4 intsum = 0; 5 for(inti = 1; I <= 100; i++){6 if(i% 2 = = 0){7Sum + =i;8 }9 }TenSystem.out.println ("and for" +sum); One } A}
Learn Java's third blog