java-recognize variables, annotations and find errors in time

Source: Internet
Author: User

Package com;
Demo of variables
public class Vardemo {
public static void Main (string[] args) {
/*
* 1) The topic does not copy 2) Note Do not write 3) must change the error
*
Practice
* 1) Declare a variable of integral type, named a
* Declare two variables of integer type named B,c
* 2) Declare integer variable D and assign value to 56
* Declare integer variable e,
* Assign a value of 56 to the variable E
* 3) declares an integer variable F and assigns a value of 5,
* Declare integer variable g and assign value to f+20, Output g
* Declare integer variable h and assign value to 5.67------------???
* The value of the output m---------------------------???
* Declare integer variable m, output m value-------------???
* 4) Declare a few correct and several wrong variables
*/







/*
4. Name of the variable:
int a1,a_5$,_6b,$_c;
int a*b; Compile error, cannot contain special characters such as * number
int 1a; Compile error, cannot start with a number
int a=5;
System.out.println (A); Compile errors, strictly case-sensitive
int class; Compile error, cannot use keyword
int age; Correct, but not recommended
int age; Suggested "English name and understanding"
*/

/*
3. Use of variables:
1) The use of the variable is the use of the number it has stored
2) The use of variables must match the data type
3) variables must be declared and initialized before they are used
int a = 5;
int b = a+10; Remove the value of a of 5, plus 10, and then assign to the integer variable b
System.out.println (b); Value of output variable b 15
System.out.println ("B"); B, as-is output in double quotes

int c = 3.14; Compilation error, data type mismatch

System.out.println (m); Compilation error, m not declared
int m;
System.out.println (m); Compilation error, m not initialized
*/

/*
2. Initialization of variables: first time assignment
int a = 250; Declares an integer variable A and assigns a value of 250
int b; Declaring an integer variable b
b = 250; Assign a value of 250 to variable B
*/

/*
1. Declaration of variables:
int A; Declare a variable of integer type named a
int b,c,d; Declares a variable of three integers named B,c,d
*/
}
}

More exciting after the update, reprinted annotated!

java-recognize variables, annotations and find errors in time

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.