Java & lab report summarizes the third week (1)

Summary: unconsciously, the third week, recalled this week, I'm more in-depth understanding of the main methods, in addition to learning the two keywords, a this, a static, this property when stressed, can only put the first cycle and can not be invoked in the sentence, static declaration calling for the class name. As well as work hard, a little better than C simple!

Experiment (a)
1. Print narcissistic number
experiment code:
public class the Hello {
public static void main (String [] args) {
for (int I = 100; I <1000; I ++) {
int I = A / 100;
int = I B / 10% 10;
int I C = 10%;
IF (Math.pow (A,. 3) + Math.pow (B,. 3) + Math.pow (C,. 3) == I) {
the System. Out.println (I);
}
}
}
}

Run shot

2.求13-23+33-43+···+973-983+993-1003的值
实验代码:
public class Hello{
public static void main(String[] args){
int sum=0;
int flag=1;
for(int i=13;i<=1003;){
sum=i*flag+sum;
flag=-flag;
i=i+10;
}
System.out.println(sum);
}
}

Run shot

3.求1!+2!+3!+···+20!的值
实验代码:
public class Hello{
public static void main(String args[]){
int sum=0;
int i,j;
for(i=1;i<21;i++){
k=1;
for(j=1;j<=i;j++){
k*=j;
}
sum+=k;
}
System.out.println(sum);
}
}

Run shot

88 + 8 + 4 888 seeking + ··· and the front 10 of the
experiment code:
public class the Hello {
public static void main (String [] args) {
int I;
int n-= 0, SUM = 0;
for (I . 1 =; I <= 10; I ++) {
n-n-* = + 10. 8;
SUM n-+ =;
}
System.out.println (SUM);
}
}

Run shot

5.求1000之内的完数
实验代码:
public class Hello{
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);
}
}
}
}

Run shot

6. request satisfies 1 + 2 + 3 + ··· n <8888 the largest positive integer
experiment code:
public class the Hello {
public static void main (String args []) {
int n-= 0, SUM = 0;
the while (SUM <8888) {
n-+ =. 1;
SUM n-+ =;
}
System.out.println (n-);
}
}

Run shot

7.用for循环打印三角形
实验代码:
public class Hello{
public static void main(String[] args) {
int i,j;
for(i=1;i<=5;i++){
for(j=5-i;j>0;j--){
System.out.print(" ");
}
for(j=1;j<=i;j++)
System.out.print("* ");
System.out.print("\n");
}
}
}

Run shot

Guess you like

Origin www.cnblogs.com/Vennien/p/11518673.html