Java & lab report summarizes the third week of a course

The third week Lessons Learned

1. With regard to the specific content of some object-oriented, understand Java classes and objects, and encapsulation and construction methods as well as knowledge of the objects anonymous.

2.this keyword, which is a member of the class attribute indicates the (variable), must be placed on the first line when using this constructor can not be calling the cycle, this only represents the current object.

3.static keywords are declared static properties of the object attributes can share with the static method declaration allows the class name to be called directly, that is, static methods.

4.main method must be defined as public static void main (String args []), and the main role of learning relevant

5. feel easy to write code or use Eclipise a little while, I want to try to write code Eclipise later.

6. blink of an eye they have to learn Java for three weeks, starting from the previously poorly understood, and now can own to solve some practical problems, we hope to be able to continue, not forgetting the beginning of the heart, was always square.

experimental report

1. All printout "Narcissus number", called "Narcissus number" refers to a three-digit number, digits of which is equal to the number of cubic and itself, for example, 153 is a "Narcissus number."

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

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

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

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

public class Jie{
      public static void main(String args[]){
                long sum = 1;
                long func = 1;
         for(int i = 2;i<=20;i++){
               func = func*i;
               sum += func;
          }
         System.out.println(sum);
     }
}

4. Calculate 8 + 88 + 888 + ..... ...... sum of the first ten.

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

5. If a number is exactly equal to the sum of its factors, this number is called the complete number. All well finished output within 1000.

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

6. Output maximum positive integer 1 + 2 + 3 ...... + n <8888's.

public class Zhen{
      public static void main(String args[]){
            int sum = 0;
            int i = 1;
            whlie(sum <= 8888){
                   sum += i;
                   i++;
           }
           Syetem.out.println(i-2);
      }
}

7. Allow for print heart-shaped loop.

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

Guess you like

Origin www.cnblogs.com/buxiu888/p/11516791.html