Lessons Learned and third week test report (a)

Test report (a)

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:

 

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) {
		int a,b,c;
		for(int i=100;i<=999;i++) {
			a=i/100;
			b=(i%100)/10;
			c=i%10;
			if(i==Math.pow(a, 3)+Math.pow(b, 3)+Math.pow(c, 3)) {
				System.out.println(i);
			}
		    }
	}
}

The results:

 

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

Experiments Source:

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) {
		int value1=13,value2=23,sum=0;
		for(;value2<=1003;) {
			sum=sum+value1+value2;
			value1+=10;
			value2+=10;
		}
		System.out.println(sum);
	}
}

The results:

 

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

Experiments source;

 

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) {
		int sum=1,SUM=0;
		
		for(int i=1;i<=20;i++) {
			sum=sum*i;
			SUM=SUM+sum;
		}
		System.out.println(SUM);
	}
}

  The results:

 

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

Experiments Source:

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) {
		int a=8,sum=0;
		for(int i=1;i<=10;i++) {
			sum=sum+a;
			a=(8+a*10);
		}
		System.out.println(sum);
	}
}

  The results:

 

 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 :

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) 
	{
		int sum=0;
		for(int i=1;i<=1000;i++)
		{
			for(int j=1;j<=i/2;j++)
			{
				if(i%j==0)
				{
					sum=sum+j;
				}
			}
			if(i==sum)
			{
				System.out.println(i);
			}
			sum=0;
		}
         }
}

  The results:

 

 

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

Experiments Source:

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) 
	{
		int sum=0;
		for(int i=1;sum<8888;i++)
		{
			sum=i+sum;
			if(sum+i>8888)
			{
				System.out.println(i);
				break;
			}
		}
	}
}

  The results:

 

 7. Use for the print cycle following pattern.

 

 

Experiments Source:

import java.util.Scanner;
public class Text1 
{

	public static void main(String[] args) 
	{
		int value1=5,point=1;
		for(int i=1;i<=5;i++){
			point=1;
			for(int j=1;;j++){
				if(j<=value1){
					System.out.print(" ");
				}
				else{
					for(int a=1;a<=i;a++){
						System.out.print("* ");
						if(a==i){
							System.out.print("\n");
							point=0;
							break;
						}
					}
				}
				if(point==0){
					break;
				}
			}
			value1--;
		}
	}
		
}

  The results:

 

 to sum up:

The main experiment are biased basis, there are certain basic C language is not difficult, most of them examined the common loop structure and branch structure, I am what is worth mentioning that no problems during the experiment.

 

 

The third week Lessons Learned

 

 

1, encapsulation

 

Package attribute: Private property type name

 

Method for the packaging: Private Method name method returns a value (parameter list) {}

 

As long as the attribute is encapsulated, and must be set by the setter and getter methods to obtain.

 

setter and getter and can quickly build in the source options on the eclipse.

 

 

 

2, the configuration method

 

Constructors and properties used to initialize the program initialization.

 

Statement constructor need to comply with the following points:

 

① constructor must match the class name.

 

② statement of the constructor can not have any return value type declaration.

 

③ can not use the return value in a return value constructor.

 

 

 

Constructor defined format:

 

 

 

{class class name

 

      Access class name (parameter 1 Type 1, Type 2 parameter 2, ......) {

 

              Program statements;

 

             ...... // constructor has no return value

 

                     }

 

   }

 

 

 

3, this keyword

 

this key has the following functions:

 

① emphasis on calling this class.

 

② The member attribute class (variable).

 

③ call the constructor method (to be placed on the first line and the call can not be recycled)

 

④ represents the current object.

 

 

 

4, static keyword

 

If you use a static declaration property, this property is called global attributes (some also called static properties).

 

When we need a large number of objects to modify the properties for the same result, you can instead use static public property the property.

 

Class attribute call:

 

.Static class name property

 

 

 

Declared static method:

 

Static may be used when declaring property, you can also use it to declare a method, a method which is sometimes called the statement "class method" can be called directly by the class name.

 

 

 

5, Java common memory area:

 

① stack memory: save all object names (save the address reference heap memory space)

 

② heap memory: to save the contents of the specific properties of each object.

 

③ global data: type of static storage properties.

 

④ global code District: Save all method definitions.

 

 

 

Guess you like

Origin www.cnblogs.com/noacgnnolife/p/11519432.html