代码如下
class Demo9 {
public static void main (String[] args) {
int a = 30 ;
int b = 0 ;
int e = 0;
int n = 1;
double d ;
int r;
int c = 7;
boolean bl = true;
boolean bt = true;
while (bt) {
n++;
if (n==0) {
bt= false;
}
d = Math.random();
r = (int)(d*10);
if (d > 0.5) {
a+=1;
if (a > 60) {
a=60;
}
} else {
a-=1;
if (a < 1) {
a = 1 ;
}
}
c++;
if (c == 7) {
bl = !bl;
}
c%=7;
e = 7-c;
if (bl) {
for (int c2 = 0; c2 < e ; c2++ ) {
System.out.print(" ");
}
System.out.print("*");
for (int c1 = 0; c1 < c ; c1++ ) {
System.out.print(" ");
}
} else {
for (int c1 = 0; c1 < c ; c1++ ) {
System.out.print(" ");
}
System.out.print("*");
for (int c2 = 0; c2 < e ; c2++ ) {
System.out.print(" ");
}
}
System.out.print(r);
for ( int i = 0; i < a ; i++ ) {
System.out.print(" ");
}
System.out.print("*");
b = 60-a;
for ( int j = 0;j < b ; j++ ) {
System.out.print(" ");
}
System.out.print(9-r);
if (bl) {
for (int c1 = 0; c1 < c ; c1++ ) {
System.out.print(" ");
}
System.out.println("*");
} else {
for (int c2 = 0; c2 < e ; c2++ ) {
System.out.print(" ");
}
System.out.println("*");
}
}
}
} |