A lab report
title
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."
Write Java programs, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.
Programming seek 1! +2! +3! + ... + 20 !.
Write Java programs, the calculation 8 + 88 + 888 + 10 ... and before it.
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.
Write applications, the output of the maximum positive integer satisfying 1 + 2 + 3 + ... + n <8888's.
For the following cycle using FIG print (isosceles triangle)
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 flowers {
public static void main(String[] args) {
int a,b,c;
int sum=0,i;
for (i=10;i<=99;i++)
{
a=i/10;
b=(i%10)/1;
c=i%1;
sum=a*10+b*1+c;
if (Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==sum)
{
System.out.println(i);
}
}
}
}
2, the experimental results
Second, write Java programs, find the value of + 13-23 + 33-43 + 973-983 + 993-1003 ... of.
1, experiment code
public class zhi {
public static void main(String[] args) {
int i,a=0,b=1,c=3;
for (i=1;i<=100;i++)
{
a=a+b*(c+(i*10));
b=-b;
}
System.out.println(a);
}
}
2, the experimental results
Third, the program seeking 1! +2! +3! + ... + 20 !.
1, experiment code
public class three{
public static void main(String[] args) {
int a,b;
long c=1,sum=0;
for (a=1;a<=20;a++) {
for (b=1;b<=a;b++) {
c=c*b;
}
sum=sum+c;
c=1;
}
System.out.println(sum);
}
}
2, the experimental results
Fourth, write Java programs, the calculation 8 + 88 + 888 + 10 ... and before it.
1, experiment code
public class and {
public static void main(String[] args) {
long a=0,b=0,i;
for (i=1;i<=10;i++)
{
a=a*10+8;
b=b+a;
}
System.out.println(b);
}
}
2, the experimental results
V. If the 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.
1, experiment code
public class perfect {
public static void main(String[] args) {
int a,b,c;
for (b=1;b<=1000;b++) {
int sum=0;
for (c=1;c<b;c++) {
if (b%c==0){
sum=sum+c;
}
}if (sum==b){
System.out.println(b);
}
}
}
}
2, the experimental results
Sixth, the preparation of the application, output the maximum positive integer satisfying 1 + 2 + 3 + ... + n <8888's.
1, experiment code
public class number {
public static void main(String[] args) {
int a,sum=0;
for (a=1;sum+a<8888;a++) {
sum=sum+a;
}
System.out.println(a-1);
System.out.println(sum);
}
}
2, the experimental results
Seven, use a for loop to print the following chart (isosceles triangle)
1, experiment code
public class copy {
public static void main(String[] args) {
int a,b,n=5;
for (a=1;a<=n;a++) {
for (b=1;b<=n-a;b++) {
System.out.print(" ");
}
for (b=1;b<=a;b++) {
if (a==b) {
System.out.print("*");
}
else {
System.out.print("* ");
}
}
System.out.println("\n");
}
}
}
2, the experimental results