java请从1打印到100,共如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

请从1打印到100,共如下:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
用单个for循环
只有一个


   1
   2   3
   4   5   6
   7   8   9  10
  11  12  13  14  15
  16  17  18  19  20  21
  22  23  24  25  26  27  28
  29  30  31  32  33  34  35  36
  37  38  39  40  41  42  43  44  45
  46  47  48  49  50  51  52  53  54  55
  56  57  58  59  60  61  62  63  64  65  66
  67  68  69  70  71  72  73  74  75  76  77  78
  79  80  81  82  83  84  85  86  87  88  89  90  91
  92  93  94  95  96  97  98  99 100

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-09
import java.io.*;
class test
{
public static void main (String[] args) throws java.lang.Exception
{

int cline=1;
int tline=0;
for(int i=1 ;i<101;i=i+1){
if (i==cline+tline){
System.out.println(i+" ");
tline=tline+cline;
cline++;
}else{
System.out.print(i+" ");
}
}
}
}本回答被提问者采纳
第2个回答  2016-12-09
int num = 1;
int line = 1;
while (num <= 100) {
int temp = 0;
for (int i = num; i < num + line; i++) {
if (i <= 100) {
System.out.print(i + " ");
temp = i;
}
}
num = temp + 1;
line++;
System.out.println();
}
输出结果:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100
第3个回答  2016-12-09
int last=1;//每一行末尾的数
int cha=1;//相邻两行末尾的数的差值
for(int i=1;i<=100;i++){
System.out.print(i+" ");
if(i==1){//i等于1时特殊处理
last=i;
cha=cha+1;
System.out.println();
}
if(last+cha==i){//上一行末尾的数加差值等于i时,换行
last=i;
cha=cha+1;
System.out.println();
}
}
相似回答