The first test summary report

First, the purpose of the experiment
are familiar with JDK development environment

Master structured programming methods

Second, the experiment content
1, print out 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 Java programs, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.
3, Programming seek 1! +2! +3! + ... + 20 !.
4, write Java programs, the calculation 8 + 88 + 888 + 10 ... before the sum.
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, the preparation of the application, output the maximum positive integer satisfying 1 + 2 + 3 + ... + n <8888 's.
7, using the following printing cycle for FIG (isosceles triangle)

Third, the progress of the experiment
1, the printout of all "Number of daffodils", 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 code

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

Screenshot experiment

2, write Java programs, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.
Experiments source code

public class 奇数和{
    public static void main(String[] args){
        int i,k=1,sum=0;
                                 for(i=3;i<=993;i++){
                        i=i+9;
            sum=sum+i*k;
            k=-1*k;
        }
           System.out.print("sum="+sum); 
          }
}

Screenshot experiment

3, Programming seek 1! +2! +3! + ... + 20 !.
Experiments source code

public class 阶乘 {
    public static void main(String[] args) {
            int i;
            long j=1,sum=0;
            for(i=1;i<=20;i++){
                j*=i;
                sum=sum+j;
            }
            System.out.print(sum);


    }


}

Screenshot experiment

4, write Java programs, the calculation 8 + 88 + 888 + 10 ... before the sum.
Experiments source code

public class 和 {

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

Screenshot experiment

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 code

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

}

Screenshot experiment

6, the preparation of the application, output the maximum positive integer satisfying 1 + 2 + 3 + ... + n <8888 's.
Experiments source code

public class 最大正整数 {
    public static void main(String[] args){
         int i=1,s=0;
         while(s<8888){
             i++;
             s+=i;
         }
         System.out.print(i-1);
    }

}

Screenshot experiment

7, using the following printing cycle for FIG (isosceles triangle)
test source code

public class 输出图形{

    public static void main(String[] args) {
        for (int i=1;i<=5;i++){
            for (int x=1;x<=5-i;x++){
                System.out.print(" ");
            }
            for (int y=1;y<=i;y++){
                System.out.print("*");
                   for (int z=1;z<=i-1;z++){    
                   }
                   System.out.print(" ");
            }
                System.out.println();
        }

    }

}

Screenshot experiment

Learn summarize
the experimental subject is relatively still pretty good, to have the idea of what direction to go to programming, in addition to a small problem behind the two questions, the other better, to deepen some java also familiar with the operation.

This week the teacher talked about some keyword usage, such as this keyword, static keywords, etc., there are some java constructor, and data storage and so on. These require a good digestion, feeling very important.

Guess you like

Origin www.cnblogs.com/zzaf/p/11522149.html