• 如果您觉得本站非常有看点，那么赶紧使用Ctrl+D 收藏吧

java流程控制之习题

2周前 (10-17) 16次浏览
经过近段时间的学习，差不多也掌握了java的流程控制以及基本知识，下面就来一起练练习题吧，看能做出来几道。

1. 打印 7行的实心菱形

2. 打印11行的实心梯形
3. 打印13行的实心的等腰直角三角形

```        int a1 = 0;
for (int i1 = 0;i1<=100;i1++){
for (int i2 = 0;i2<=50;i2++){
for (int i5=0;i5<=20;i5++){
for (int i10=0;i10<=10;i10++){
for (int i20=0;i20<=5;i20++){
for (int i50=0;i50<=2;i50++){
if (i1*1+i2*2+i5*5+i10*10+i20*20+i50*50==100){
a1++;
}
}
}
}
}
}
}
System.out.println(a1);```

```        double money2 = 100.0;
double kele2 =3.0;
double a2 = 3.0;
double b2 = 2.0;
double c2 = b2/a2;
int d2 = 0;
for (int i2 = 0;money2>kele2;i2++){
money2 = money2 - kele2;
kele2 =kele2 + kele2 * c2;
d2++;
if (d2%2==0){
d2++;
}
}
System.out.println(d2);```

1. 打印 7行的实心菱形

2. 打印11行的实心梯形
3. 打印13行的实心的等腰直角三角形

```　　　　　//菱形
for(int i3=1;i3<=4;i3++){
for (int a3=1;a3<=4-i3;a3++){
System.out.print(" ");
}
for(int a3=1; a3<=(2*i3-1);a3++){
System.out.print("*");
}
System.out.println();
}
for(int i3=3;i3>=1;i3--){
for (int a3=1;a3<=4-i3;a3++){
System.out.print(" ");
}
for(int a3=1; a3<=(2*i3-1);a3++){
System.out.print("*");
}
System.out.println();
}//梯形
for (int i = 3;i<=13;i++){
for (int a=1;a<=13-i;a++){
System.out.print(" ");
}
for (int c=1;c<=(2*i-1);c++){
System.out.print("*");
}
System.out.println();
}
//直角三角形
for (int i =1;i<=12;i++){
for (int i1=1;i1<=i;i1++){
if (i==i1||i1==1){
System.out.print(" "+"*");
}else{
System.out.print(" "+" "+" ");
}
}
System.out.println("");
}
System.out.println(" *  *  *  *  *  *  *  *  *  *  *  *  *");
```

```        //第四题
int a4 = 1;
int c4 = 0;
for (int i4 = 1; i4<=10;i4++){
for (int b4 =1;b4<=i4;b4++){
a4=a4*b4;
}
c4=c4+a4;
a4=1;
}
System.out.println(c4);```

```        int month = 12;
long a = 1l,b = 1l,c = 0l;
for (int i = 0;i < month-2;i++){
c = a + b;
a = b;
b = c;
}
System.out.println("拥有"+c+"只兔子");```

```        int a6 = 999;
int b6 = 1;
for (int i = 1; i<=10;i++){
if (a6/10!=0){
b6++;
a6=a6/10;
}else{
break;
}
}
System.out.println(b6);    ```

```        int a7 =20;
for (int i7=1;i7<=a7;i7++){
for (int b7=1;b7<=a7;b7++){
if (i7*b7==a7&&b7!=a7){
System.out.print(b7+" ");
}
}
}```

```       int a8 =20;
int b8 =10;
int max = 0,min = 0;
if (a8>b8){
int t = a8;
b8 = a8;
a8 = t;
}
for (int i=1;i<=a8;i++){
if (a8%i==0&&b8%i==0){
max=i;
}
}
min=a8*b8/max;
System.out.println(max);
System.out.println(min);```

```        int a9 =0;
int c9 =0;
for (int i9=2;i9<=1000;i9++){
for (int b9=1;b9<i9;b9++){
if (i9%b9==0){
a9+=b9;
}
}
if (a9==i9){
c9+=a9;
}
a9=0;
}
System.out.println(c9);```

```        int a10 = 0;
int y1=0;
int y2=0;
int y3=0;
int y4=0;
int y5=0;
int y6=0;
int y7=0;
int y8=0;
int y9=0;
int y0=0;
for (int i10=1;i10<=100000;i10++){
a10=i10+a10;
switch (a10%10){
case 1:
y1++;
break;
case 2:
y2++;
break;
case 3:
y3++;
break;
case 4:
y4++;
break;
case 5:
y5++;
break;
case 6:
y6++;
break;
case 7:
y7++;
break;
case 8:
y8++;
break;
case 9:
y9++;
break;
case 0:
y0++;
break;
}
}
System.out.println("1 "+y1);
System.out.println("2 "+y2);
System.out.println("3 "+y3);
System.out.println("4 "+y4);
System.out.println("5 "+y5);
System.out.println("6 "+y6);
System.out.println("7 "+y7);
System.out.println("8 "+y8);
System.out.println("9 "+y9);
System.out.println("10 "+y0);```