I'm having trouble having my code outputting correctly. I have gotten it right except for the spaces part (first nested for loop).
我无法正确输出代码。除了空间部分(首先嵌套for循环)之外,我已经把它弄好了。
public class Practice {
public static void main(String[] args) {
Top();
}
public static void Top() {
for (int a = 1; a <= 5; a++) {
for (int b = 1; b <= 5; b++) {
System.out.print(" ");
}
for (int c = 1; c <= a; c++) {
System.out.print("/");
}
System.out.print("**");
for (int d = 1; d <= a; d++) {
System.out.print("\\");
}
System.out.println();
}
}
}
Desired output:
/**\
//**\\
///**\\\
////**\\\\
/////**\\\\\
1 个解决方案
#1
0
Change the line:
换行:
for (int b = 1; b <= 5; b++) {
to:
for (int b = 1; b <= 5 - a; b++) {
#1
0
Change the line:
换行:
for (int b = 1; b <= 5; b++) {
to:
for (int b = 1; b <= 5 - a; b++) {