java first experiment Summary & third weekly summary

Java first experiment report, java development environment with simple Java program

I. Purpose

Familiar development environment JDK
2. The master structured programming methods

II. Experimental 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 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 ... and before it.

  5. If it is exactly equal to a number of factors and, this number is called the complete number. All finished programming the number of output within 1000.

  6. Write applications, the output of the maximum positive integer satisfying 1 + 2 + 3 + ... + n <8888's.

  7. Use a for loop to print the graphic below
           *
          * *
         * * *
        * * * *
       * * * * *

III. Experimental procedure

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 Timu1 {
    
        public static void main(String[] args) {
            int x, y, i, j, k;
            for(i = 100;i < 999;i ++) {
                x = i % 10;
                y = i / 10;
                j = y % 10;
                k = y / 10;
                if(Math.pow(x, 3) + Math.pow(j, 3) + Math.pow(k, 3) == i) {
                    System.out.println(i);
                }
                        
            }
        }

    }
  • Experimental results

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

  • Experiments source

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

}


  • Experimental results

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

  • Experiments source

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

}
  • Experimental results

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

  • Experiments source
public class Timu4 {
    public static void main(String[] args) {
        int   i , y = 8;
        long sum = 0,x = 8;
        for(i = 1;i <= 10;i++ ) {
            sum = sum + x;
            x = (x * 10 ) + y;
        }
        System.out.println(sum);
    }
    
}


  • Experimental 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
public class Timu5 {
    public static void main(String[] args) {
        int i, j, sum;
    for(i=0;i<=1000;i++){
        if(i==1) continue; 
        sum=1;
        for(j=2;j<i;j++) 
            if(i%j==0) sum+=j;
        if(sum == i){   
        System.out.println(i);  
        }
        }
    }

}


  • Experimental results

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

  • Experiments source
public class Timu6 {
    public static void main(String[] agrs) {
        int i, sum = 0;
        for(i = 0;sum + i< 8888; i++) {
            sum = sum + i;
        }
        System.out.println(i - 1);
        System.out.println(sum);
    }
    

}

  • Experimental results

7. Use for the print cycle following pattern

           *
          * *
         * * *
        * * * *
       * * * * *
  • Experiments source
public class Timu7 {
    public static void main(String[] args) {
        int i, j, x = 4,k,l = 4;
        for(i = 0;i < 5;i++) {
            for(j = x;j > 0;j--) {
                System.out.print(" ");
            }
            x = x -1;
            for(k = l;k < 5;k++) {
            System.out.print("* ");
        }
            System.out.print("\n");
            l--;
    }
    }
}


  • Experimental results

to sum up:

The lab report is the first Java lab reports, although the topic is not very difficult, but the purpose of this test report is intended to familiarize us with jdk development environment, I believe that this purpose has been achieved, and even some problems because the front to do there may be some do not understand that this time will be skilled to do, find it difficult to understand the topic before those now doing it very smooth, can immediately think of a solution, even more than one method. In short the test report or rewarding.

The third weekly summary

This week talked about construction methods, anonymous objects, this keyword, static keyword.

Construction method:

Construction method is used when an object is instantiated

per = new Person();

As used herein constructor
which is defined manner similar to the conventional method but the idea in mind:

  • 1. Name of the class constructor must match the name;
  • 2. Statement of the constructor does not have any return value type declaration;
  • 3. You can not use the constructor returns a return value;
    as long as the class constructor must exist than the previous program does not constructor, if it is explicitly declared a constructor, it will automatically generate a compile-time what is not do constructor; it is just that the previous program does not declare the constructor, objects can also be instantiated operation object;

When overloaded; if a class has been clearly declared a constructor, the program at compile time will not generate a default constructor; there is a constructor in a class at least, that can be overloaded constructor All overloaded method according to the number of parameters from more to less, or from less to more.

Anonymous object:

Object anonymous object, it is not given a clear name, anonymous objects generally used only once, and only in an anonymous object heap memory space to open up, there is no reference to the stack memory. Anonymous objects in the actual development is substantially passed as a parameter of the instances of another class object.

this keyword:

1. this call this class attributes


When the need for such an assignment would require the this keyword

2. Use this constructor call
if you have more than one constructor in a class, can be performed using this keyword to call each other

  • With the idea to call the constructor this constructor needs to be placed first line
  • Calls can not be recycled
  • Can only call the constructor in the constructor
    3.this represents the current object

The main feature is the comparison object


4. Stresses call this class method
is to play a role emphasized.

The static keyword

1. declared static properties
if the properties are declared static in the program, then this property is called global properties, or static property
attribute speaking in front of a stack memory, heap memory, in addition there is a global data area, static declaration it is on the inside

2. using static method declaration:
static either declare property, you can also declare a method, a method which is sometimes called the statement "class method" can be called directly by the class name

It must be noted that the non-static method can be declared static to call a property or method declaration, but the method is declared static properties or methods can not call non-static type declaration of.
3. appreciated main () method:

Guess you like

Origin www.cnblogs.com/xiao--liang/p/11496131.html