怎么用java打出下图 1 121 12321 1234321

怎么用java打出下图
1
121
12321
1234321
。。。。。。。
12345678987654321

第1个回答  2017-04-29
package com.norwaya;

public class Test01 {

public static void main(String[] args) {

forEach(9);
}

private static void forEach(int num) {
if (num == 0)
return;
forEach(num - 1);
paintMins(num - 1, p -> System.out.print(p));
System.out.print(num);
paintPlus(num - 1, p -> System.out.print(p));
System.out.println("\n");
}

private static void paintMins(Integer num, Tool tool) {
if (num > 0) {
paintMins(num - 1, tool);
tool.print(num);

}
}

private static void paintPlus(Integer num, Tool tool) {

if (num > 0) {
tool.print(num);
paintPlus(num - 1, tool);
}
}
interface Tool {
void print(int num);
}
}

//log:
1

121

12321

1234321

123454321

12345654321

1234567654321

123456787654321

12345678987654321

本回答被网友采纳

java编程题求解:使用for语句打印显示下列数字: 1 121 12321 1234321
public static void main(String[] args) { for (int i = 1; i < 5; i++) { for (int j = 1; j < i; j++) { System.out.print(j);} for (int j = i; j >= 1; j--) { System.out.print(j);} System.out.print(" ");} } ...

...不胜感激。 1 121 12321 1234321 123454321
int main(int argc, char *argv[]){ int i,j;for(i=1;i<=N;i++){ printf("%*c",N+1-i,' ');for(j=1; j<=(2*i-1)\/2; j++)printf("%d",j%(i+1));for(j=(2*i)\/2; j>=1; j--)printf("%d",j%(i+1));printf("\\n");} getch();} ...

...层数在程序运行时由键盘输入 1 121 12321 1234321
int main(){ int i,j,k=1,temp;printf("please input your layer:");scanf("%d",&temp);if(temp>10){ printf("input wrong");} printf("\\n");for(i=1;i<=temp;i++){ k=1;for(j=1;j<=temp-i;j++)printf(" ");for(;j<=temp;j++)printf("%d",k++);for(k=k-2;k...

PASCAL 打印 1 121 12321 1234321 123454321 12345654321
begin readln(n); \/\/n为行数 for i:=1 to n do begin write('':n-i);for j:=1 to i do write(j);for j:=i-1 downto 1 do write(j);writeln;end;end.如果您只需要在同一排上输出,那么用下面一段代码 var n,i,j:integer;begin readln(n);\/\/n为一共有多少个数 for i:=...

...用c语言写。 1 121 12321 1234321 12321 121 1
void output(int n){ int i,j,temp;for(i=1;i<=n;i++){ temp=n-i;while(temp--)printf(" ");for(j=1;j<=i;j++)printf("%d",j);for(j=i-1;j>=1;j--)printf("%d",j);printf("\\n");} for(i=n-1;i>=1;i--){ temp=n-i;while(temp--)printf(" ");for(j...

怎么用Python打出这样的字符串? 1 121 12321 1234321
quick brown fx jmps v t lazy dg'>>> remove_duplicates("121 balloons 2 u")'121 balons 2 u'"""ret = []for l in raw:if l in string.letters and l in ret:continue ret.append(l)return "".join(ret)if __name__ == '__main__':import doctest doctest.testmod()...

...为1,第二行为121,第三行为12321,第四行为1234321
Cls Dim i As Integer, j As Integer, N As Integer N = 9 For i = 1 To N 'debug.Print For j = -N To N If j + i < 1 Then Print " ";ElseIf j > i - 1 Then Exit For ElseIf j > 0 Then Print i - j;Else Print j + i;End If Next j Print Next i ...

VB中数字金字塔 样式为:1 121 12321 1234321 以此类推,请问这个程序该...
Private Sub Command1_Click()For i = 1 To 9 Print Spc(9 - i);For j = 1 To i Print Chr(48 + j);Next j For j = i - 1 To 1 Step -1 Print Chr(48 + j);Next j Print Next i End Sub

用pascal语句打印下列图形: 1 121 12321 1234321 12321 121 1
能用麻溜结贴,不能用继续追问。program PrintTriangle;const LEVEL = 4;var row, col, max, num: Longint;begin max := 0;for row := 1 to LEVEL * 2 - 1 do begin if row <= LEVEL then Inc(max)else Dec(max);Write(' ':LEVEL - max + 1);num := 0;for col := 1 to...

1 121 12321 1234321 C语言程序用for循环,怎么编
int i,j;for(i=1;i<5;i++){ for(j=1;j<=i;j++)printf("%d",j); \/*打印前半部分*\/ for(j=i-1;j>0;j--)printf("%d",j);\/*打印后半部分*\/ printf(" "); \/*打印空格部分*\/ }

相似回答