Learn Java's third blog

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.