for - 急 JAVA 各位幫幫忙

3 views
Skip to first unread message
Message has been deleted

q738...@yahoo.com.tw

unread,
Dec 22, 2010, 11:25:23 PM12/22/10
to EnJoyJava
import java.util.Scanner;

class Text {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
System.out.println("請輸入高度");
int high = in.nextInt();
System.out.println("請輸入階數");
int level = in.nextInt();
for (int i = 0; i < level; i++) {
for (int j = 1; j < high+1; j++) {
for (int k = 0; k < (level-i)+(high-j); k++) {
System.out.print(" ");
}
for (int o = 1; o < (j*2)+(i*2); o++) {
System.out.print("*");
}
System.out.println();
}
}
for (int i=0; i<3; i++) {
for (int k = 0; k < (level+high)-2; k++) {
System.out.print(" ");
}
for (int j = 0; j < 3; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
Reply all
Reply to author
Forward
0 new messages