3个回答
展开全部
public class A {
public static void main(String[] args) {
int num = 6;
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j+" ");
}
System.out.println();
}
}
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
把for (int j = 1; j <= i; j++) { 变成for (int j = 1; j <= num-i; j++) {
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
public static void main(String[] args) {
int num = 6;
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j+" ");
}
System.out.println();
}
}
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
把for (int j = 1; j <= i; j++) { 变成for (int j = 1; j <= num-i; j++) {
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
展开全部
public class DemoTest {
/**
* @param args
*/
public static void main(String[] args) {
printNum(5);
printNumOrder(5);
}
private static void printNum(int num){
for (int i = 1; i <= num; i++) {
for (int j = 0; j < i; j++) {
System.out.print(j+1);
}
System.out.println();
}
}
private static void printNumOrder(int num){
for (int i = num; i >= 1; i--) {
for (int j = i; j >= 1; j--) {
System.out.print(j);
}
System.out.println();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
printNum(5);
printNumOrder(5);
}
private static void printNum(int num){
for (int i = 1; i <= num; i++) {
for (int j = 0; j < i; j++) {
System.out.print(j+1);
}
System.out.println();
}
}
private static void printNumOrder(int num){
for (int i = num; i >= 1; i--) {
for (int j = i; j >= 1; j--) {
System.out.print(j);
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询