Test report (a) & third weekly summary

Java test report

 

 

Experiment a Java development environment with simple Java program

First, the purpose of the experiment

(1) be familiar with JDK development environment

(2) master structured programming method

Second, the experiment 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:

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

The results:

 

2. write Java programs, seek + 13-23 + 33-43 ... value of + 973-983 + 993-1003.

Experiments Source:

 

public class Shijia{
    public static void main(String[] args){
        int sum=0;
        for(int i=13;i<=1003;i+=10){
            
             if((i/10)%2==0){
            sum=sum-i;
            }
            else{
            sum=sum+i;
            }
        }
        System.out.println("sum="+sum);
    }
}

 

The results:

 

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

Experiments Source:

public class Jiecheng{
    public static void main(String[] args){
        long sum=0;
        int a=1;
        for(int i=1;i<=20;i++){
            a=1;
            for(int j=1;j<=i;j++){
            a*=j;
            }
            sum=sum+a;
        }
        System.out.println("sum="+sum);
    }
}

The results:

 

4. The preparation of Java programs, calculation 8 + 88 + 888 + ... before and 10 of.

Experiments Source:

 

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

 

 

The results:

5. a number of factors, if it is exactly equal to the sum, this number is called the complete number. Programming output all well finished within 1000.

Experiments Source:

 

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

 

 

 

The results:

 

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

Experiments Source:

 

public class Baqian{
    public static void main(String[] args){
        int sum=0;
        int i=1;
        do{
             sum=sum+i;
             i++;
        }while(sum<8888);
        System.out.println(sum-i);
    }
}

 

 

 

The results:

 

7. Use for the print cycle following pattern.

 

 

 

Experiments Source:

public class Triangle{
    public static void main(String[] args){
        for(int i=1;i<=5;i++){
            for(int k=1;k<7-i;k++){
                System.out.print(" ");
            }
            for(int b=1;b<=i;b++)
                                                                 System.out.print("* ");
                              System.out.println("\n");    
        }
    }
}

 

 

The results:

 

 

to sum up:

Using a simple for loop output.

 

 

Summary of the third week

 

 

A class object

对象的创建及使用

 

类名 对象名称 = null//声明对象
对象名称 = new 类名();   //实例化对象,只要有关键字new就表示开辟新的堆内存空间


class Person{
         .......
         .......

}
 ......
Person per = null;
per = new Person;
        ......

 

创建多个对象

class Person{
         .......
         .......

}
 ......
Person per1 = null;
Person per2 = null;
per1 = new Person();
per2 = new Person()
        ......

 

二、封装性

 

为属性封装:private   属性类型   属性名称;

为方法封装:private   方法返回值    方法名称(参数列表){}  

class Person{
        private String name;
        ..........
}

 

三、构造方法

class 类名称{

          访问权限   类名称(类型1  参数1,.........){

                            程序语句;

          }

}

 

class Person{
        public Person(){
                 System.out.println(“   ....”)
        }
}

 

Guess you like

Origin www.cnblogs.com/xu23/p/11493746.html