Java test report and a summary of two jobs

Java test report

Java development environment and test a simple Java program

First, the purpose of the experiment

(1) be familiar with JDK development environment

(2) master structured programming method

Second, the experimental content

1. printout of all the "number of Narcissus", the so-called "number Narcissus" means a 3-digit number, which is equal to the digits of the cube and the number itself. For example, 153 is a "number daffodils."

2. Write a Java program, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.

3. Programming seek 1! +2! +3! + ... + 20 !.

4. The write Java programs, calculation 8 + 88 + 888 + 10 ... and the front.

5. If a number is exactly equal to the sum of its factors, this number is called the complete number. All finished programming the number of output within 1000.

6. write applications, output meets + ... + n <maximum positive integer 1 + 2 + 3 8888.

7. Use for the print cycle following pattern.

Third, the experimental process

1. printout of all the "number of Narcissus", the so-called "number Narcissus" means a 3-digit number, which is equal to the digits of the cube and the number itself. For example, 153 is a "number daffodils."

Experiments Source:

 

 The results:

153
370
371
407

 

2. Write a Java program, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.

Experiments Source:

 

 The results: -500

3. Programming seek 1! +2! +3! + ... + 20! .

Experiments Source:

 

The results: 4,037,913

4. The write Java programs, calculation 8 + 88 + 888 + 10 ... and the front.

 Experiments Source:

 

 

 

 

 The results:

1286608608

 

5. If a number is exactly equal to the sum of its factors, this number is called the complete number. All finished programming the number of output within 1000.

Experiments Source:

 

 The results:

6
28
496

6. write applications, output meets + ... + n <maximum positive integer 1 + 2 + 3 8888.

Experiments Source:

 

 The results:

132

7. Use for the print cycle following pattern.

 

Fourth, the experiments summarized:

I think that we should practice more questions, add your own logic to solve related problems.

summary report:

A: class definition: basic embodiment; public static method return type name (parameter type parameter name, .......) {method body; return value return;}

Three kinds of method invocation; Note: void only for a single call; there must be a more important place! ! ! When defining the learning classes, defined when the member method and basic methods, members of the methods he does not need the static keyword, this should pay attention!

Familiar with the code! ! ! Here to explain when and when not to use the static keyword: When defining member methods do not, at this time because the method that is defined to be called by the object, rather than as previously defined together with the main methods and by the main method in a class among called directly.

   Two: to write about multiple objects to create objects of use - the object passed by reference:

    1-per2 no open heap memory space -per2 = per1-> will per1 heap memory usage rights to per2; each stack memory space can modify the contents of heap memory.

    2-per2 also opened up a heap memory space -per2 = per1-> because per2 itself has pointed heap memory space, so how would like to point per1 corresponding space, you must disconnect the existing connection. Therefore, the existing heap space, stack space is not the point, to form a space garbage, waiting for Java garbage collection for recycling. Per2 at a time can also be modified in the heap memory data per1.

  III: Encapsulation: packaging and method of packaging properties

  Property package:. Private member variables Once private, can be accessed in any class, but! Beyond the outside of this class can not directly access the range, i.e., outside of this indirect access class setting and getting accessed indirectly using setter and getter methods. This can also be controlled grammar in the method - test code. setXxx setting data, assignment, no return value, but parameters; getXxx for pick up, there is a return value, return.

  IV: Constructors: main role is assigned to the class attributes. Note book p95 constructor.

   例;class Person{

      public Person(String name,int age){

        this.name = name; // this is the case with the member variables and parameters in order to distinguish

        this.age=age;

        //this.setName(name); this refers to an object and this

        //this.setAge(age);

        }

   Five; this keyword

    1. When the method of the class member variables and local variables of the same name when, in accordance with "the principle of proximity" preferentially use local variables, if the access class member variables among the present, we can use this, this. The local member variable to distinguish Relational variables

    2. Who is calling the method which object this.

   Six Relations. Local variables and member variables (parameters also when a local variable)

    1. Define the position is not the same

      Local variables: the interior of the method;

      Member variables: the external method, in which the direct write

    2. The scope is not the same

      Local variables: only available method among;

      Member variables: the entire class among

    3. The default values ​​are not the same

      Local variables: no default, to use the manual assignment;

      Member variable: there are defaults

   Seven .static keyword

      : If the property stated in the program, then the property known as global properties, (some also called static properties). After our static global variable to the value of the property needs to be changed, it is best to call directly by the class name.

    Call format class attributes: Attribute class name .static Example: Person.country = "B city";

    Java memory commonly used in four areas

      1 stack memory: save all object names (exact address is saved cited the heap memory space)

      2 heap memory: to save the contents of specific attributes of each object

      3 and global data: type of static storage properties

      Global code area 4: save all the methods defined 

    

 

Guess you like

Origin www.cnblogs.com/changanshisanzhao/p/11522142.html