我想为java创建一个打印这种模式的程序:
最好使用像For循环这样的基本东西,但到目前为止我只能打印出这里显示的反向模式:
import java.util.Scanner;
public class Pattern {
public static void main(String[] args) {
for(int i = 6; i >= 1; --i) {
for(int j = 1; j <= i; ++j) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
发布于 2018-10-08 09:12:58
这样试试:
public static void main(String[] args) {
for(int i = 6; i >= 1; --i) {
for(int spaces=0; spaces<=6-i; i++){
System.out.print(' ');
}
for(int j = 1; j <= i; ++j) {
System.out.print(j + " ");
}
System.out.println();
}
}
https://stackoverflow.com/questions/-100002846
复制相似问题