The third week program summary test report

topic:

1. "Narcissus"

public class zuoyehuashui {
    public static void main(String[] args) {
        int x,y,z;
        int sum=0,i;
        for (i=10;i<=99;i++)
        {
            x=i/10;
            y=(i%10)/1;
            z=i%1;
            sum=x*10+y*1+z;
            if (Math.pow(x,3)+Math.pow(y,3)+Math.pow(z,3)==sum)
            {
                System.out.println(i);
            }
        }
    }

}

 

2. seek value + 13-23 + 33-43 + 973-983 + 993-1003 ... of.

public class zuoyehuashui{
    public static void main(String[] args)
    {
        int i, j = 0, k = 3;
        int flag = 1;
        for (i = 1; i <= 100; i++)
        {
            j = j + flag * (k + (i * 10));
            flag = -flag;
        }
        System.out.println(j);
    }
}

 

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

public class zuoyehuashui {
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int m = sc.nextInt();
       int sum = 0, num = 1;
       for(int i = 1;i<=m;i++)
       {
           num = num*i;
           sum = sum+num;
       }
       System.out.println(sum);
    }
}

  

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

public class zuoyehuashui{
    public static void main (String args[]) {
        long sum = 0,a = 8;
        for(int i=1;i<=10;i++) {
            sum = sum + a;
            a = a * 10 + 8; 
        }
        System.out.println(""+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.

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

  

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

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

  

7. FIG below for printing cycle (isosceles triangle)

public class zuoyehuashui{
    public static void main(String[] args) {
        int i, j;
        for(i = 1;i<=5;i++){  //限制循环次数

            for(j = 5;j>=i;j--){   
                System.out.print(" ");
            }
            for(j = 1;j<=i;j++){
                System.out.print(" *");
            }
            for(j = 5;j>=i;j--)
            {
                System.out.print(" ");
            }
            System.out.println();
        }
    }

  

 

to sum up

this usage:

  1. The method of the present class emphasizes

  2 represents the class attributes

  3. The use of this class constructor calls this method

  4.this represents the current object

 

static Keywords:

If a variable using static, that variable does not belong to the object itself, but belongs to the class itself is located.

This is a public variable multiple objects.

(Non-static method can be declared static to call a property or method declaration, but the method can not be declared static property or method call non-static type declarations)

Guess you like

Origin www.cnblogs.com/hualikun/p/11521015.html