Week Course summary test report

First, 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."

1, experiment code

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

2, run shot.

3, design ideas
this topic is designed to allow us to extract the single digits 10 100, solves this problem as long as this problem is very simple with a for loop can be resolved.
(Lee Jin class when the teacher talked about the subject) The subject did not encounter any problems.

Second, write Java programs, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.

1, experiment code

public class qiuhe{
    public static void  main(String[]args){
    int sum=0;
    int a; 
    int b;
    for(a=13;a<=1003;){
        for(b=1;b<=100;b++){
        if(b%2==0)
        sum-=a;
        else
        sum+=a;
        a+=10;
            }
        }
        System.out.println(sum);
    }
}

2, run shot

3, design ideas
this problem we have observed with 10 numbers each time, always 3 bits, bits, then remove the foregoing figures can be considered as 1 to 100, and the first digit
is odd it is a plus sign, and vice versa that is, a minus sign. So you can use a for loop to do it.

Third, the program seeking 1! +2! +3! + ... + 20 !.

1, experiment code

public class jiecheng{
    public static void main(String[]args){
    int sum=0;
    for(int a=1; a<=20; a++){
    int n=1;        
    for(int b=1; b<=a; b++){
         n*=b;
        }
        sum+=n;
        }
        System.out.println("输出总和:"+sum);
    }
}

2, run shot

3, design ideas
on this topic beginning do not know how to express factorial, then online searching to know for two cycles, said final summation on it.

Fourth, write Java programs, the calculation 8 + 88 + 888 + 10 ... before the sum

1, experiment code

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

2, run shot

3, design ideas
on this topic began with a definition of int to do, and then calculate the result and others are not counted as behind it into long type solved.

Fifth, if a number is exactly equal to the sum of its factors, this number is called the complete number. Programming output of the 1000 count them all

1, experiment code

public class wangshu{
    public static void main(String[]args){
        System.out.println("1000以内的完数有:");
    for(int i=2; i<=1000; i++){
        int sum=0;
    for(int n=1; n<i; n++){
        if(i%n==0){
        sum+=n;
            }
        }
        if(sum==i){
        System.out.println(i+"");
        }
    }
    }
}

2, run shot

3, design ideas
on this topic have not get to know, after online searching watched some code or do not understand, those two cycles are not particularly understand, but to little reaction

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

1, experiment code

public class bijiao{
    public static void main(String [] args){
    int sum=0;
    int i;
    for(i=1; sum+i<8888; i++){
        sum+=i;
        }
    System.out.println("最大整数:"+(i-1));  
    }
}

2, run shot

3, design ideas
this problem quite simply, a for loop can be resolved

Seven; for loop following FIG print (isosceles triangle)

1, experiment code

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

2, run shot

This week class learning content

1, the role of this keyword in java
(1) emphasize this method of the present class.
(2) indicates that this class are familiar.
(3) may be used according to the present call this class constructor.
(4) this represents a single object before
2, java in the static keyword
declared static properties (1) program, then this property is called global attributes (also called static properties)
static properties can not call non-static methods.
(2) static methods may be used to declare, it declares a method is sometimes called class methods, class names can be called directly.
3, be understood that main () method
public: This method can be called showing the outside.
static: indicates that this method can be called directly by the class name.
void: the main program is the starting point of the method, it does not require any return value.
main: the main system ordained default method name to call, when executed, default to find the main () method name.
String args []: parameter indicative of operation.

Guess you like

Origin www.cnblogs.com/tangjiacheng/p/11508819.html