Third Course summary and test report writing Week (a)
Java test report
Class Jike a group of Student ID 20188375 Name Tangyun Yun
Complete time
Rating scale
Experiment a Java development environment with simple Java program
First, the purpose of the experiment
(1) be familiar with JDK development environment
(2) master structured programming method
Second, the experiment content
- Printout of all "Number of daffodils", the so-called "number Narcissus" means a 3 -digit numbers which you cube and is equal to the number itself. For example, 153 is a "number daffodils."
- Write Java programs, seek + 13-23 + 33-43 ... + 973-983 + 993-1003 value.
- Programming seek 1 ! +2 ! +3 ! + ... + 20! .
- Write Java programs, the calculation 8 + 88 + 888 + ... before 10 and Paragraph.
- If it is exactly equal to a number of factors and, this number is called the complete number. Programming output 1000 all finished within a few.
- Write applications, output meets . 1 + 2 +. 3 + ... + n-<8888 largest positive integer.
- Use for loop to print the graphic below.
Third, the experimental process
1. printout of all the "number of Narcissus", the so-called "number Narcissus" means a 3 -digit numbers which you cube and is equal to the number itself. For example, 153 is a "number daffodils." |
Experiments Source:
public class Flower { public static void main(String[] args) { int n, g, s, b; for(n=100;n<1000;n++) { g=n%10; s=n/10%10; b=n/100%10; if(n==g*g*g+s*s*s+b*b*b) { System.out.println(n); } } } }
|
The results:
|
2. write Java programs, seek + 13-23 + 33-43 ... + 973-983 + 993-1003 value. |
Experiments Source:
public class Sum { public static void main(String[] args) { int n; int sum=0; for(n=1;n<=100;n++) { if(n%2==0) { sum=sum-(n*10+3); } else { sum=sum+n*10+3; } } System.out.println(sum); } }
|
The results:
|
3. 编程求1!+2!+3!+…+20!。 |
实验源码: public class Factorial { public static void main(String[] args) { long sum=0; for(int i=1;i<=20;i++) { sum+=fact(i); } System.out.println(sum); } public static long fact(int n) { long product=1; for(int i=1;i<=n;i++) { product=product*i; } return product; } }
|
实验结果:
|
4. 编写Java程序,计算8+88+888+…前10项之和。 |
实验源码:
public class Eight { public static void main(String[] args) { int i; long item=8; long sum=0; for(i=1;i<11;i++) { sum=sum+item; item=item*10+8; } System.out.println(sum); } }
|
实验结果:
|
5. 一个数如果恰好等于它的因子之和,这个数就称为完数。编写程序输出1000以内的所有完数。 |
实验源码:
1 public class WanShu 2 { 3 public static void main(String[] args) 4 { 5 int i,j; 6 for(i=1;i<=1000;i++) 7 { 8 int sum=0; 9 for(j=1; j<i; j++) 10 { 11 if(i%j==0) 12 { 13 sum=sum+j; 14 } 15 } 16 if(i==sum) 17 { 18 System.out.println( i ); 19 } 20 } 21 } 22 }
|
实验结果:
|
6. 编写应用程序,输出满足1+2+3+…+n<8888的最大正整数。 |
实验源码:
public class Bign { public static void main(String[] args) { int i; int sum=0; for(i=1; sum+i<8888; i++) { sum=sum+i; } System.out.println( i -1); } }
|
实验结果:
|
7. 使用for循环打印下面的图形。
|
实验源码:
1 public class Triangle 2 { 3 public static void main(String[] args) 4 { 5 for (int i = 0; i < 5; i++) 6 { 7 for (int j = i + 1; j < 5; j++) 8 { 9 System.out.print(" "); 10 } 11 for (int k = 0; k <= i; k++) 12 { 13 System.out.print("* "); 14 } 15 System.out.println(); 16 } 17 } 18 }
|
实验结果:
|
总结: