Apex language (two) variables and constants

1, variable

  • Where to computing operation (processing) of data is variable, used to store data and calculations to participate in operations.
  • Variables are identified by the variable name.
  • Variable names consist of alphanumeric and underscores, not beginning with a digit.

    【正确】number,number1,number_1,_number

    [Error] 1number, 1_number

  • Variable must first declare its data type can be used, such as a person ages will explain it is an integer, a person's birthday, we should state that it is a date.

    [Format] data type variable name; // variable data type introduced in the next lesson

    [Example] Integer age; // declares an integer variable

    [Example] Date birthday; // declare a variable date

 

  • Initialization variable assignment, the variable is not assigned and initialized, the initial variable is null.

    [Initialization] Integer a = 1, b, c; // variable a value assigned to a variable, while variables declared

    [Assignment] 

     Integer a = 1, b, c; // b, c declared when there is no specified value 

      b = 1; // specified value in use

      c = a + b; // specified value in use

 

  • You must have a value when the variable participate in operations.

    [Example 1] + 1 = 2 is calculated

    【correct】

     Integer a=1,b=1,c;
    c=a+b;

    [Error ]

     Integer a=1,b,c;
     c=a+b;

    【error】

    Integer a=1,b=1;
    c=a+b;

  • Variables are not case sensitive.

    【error】

     A Integer;  Double A; // A variable declared, can not be repeated statement
   

2, Constant

  • Once a variable declaration or assignment will not change their values.
  • Use the keyword final when constant declaration.
  • When throughout the program variables you should have a constant value, constant use.

    【correct】

     final Double PI=3.14 ;

    【error】

     final Double PI=3.14 ;
     PI=PI+1;

3, an example of

(1) 5 + 6, and seek

 

(2) the known radius 10, of circular perimeter and area

 

Apex语言(一)开发环境

Apex语言(三)原始数据类型

 

     

 

Guess you like

Origin www.cnblogs.com/drink186/p/10966988.html