蓝桥杯(java C组)省赛真题:打印数字

**

打印数字

**
小明写了一个有趣的程序,给定一串数字。
它可以输出这串数字拼出放大的自己的样子。

		比如“2016”会输出为:
		 22222   00000       1   6666
		2     2 0     0    1 1  6
  			  2 0     0      1  666666
 			2  	0     0      1  6     6
		  2     0     0      1  6     6
		2     2 0     0      1  6     6
		2222222  00000     1111  66666
package Lqb;

public class Text3 {
		
	public static void main(String[] args) {
		f(2016);

	}
	static void f(int n)
	{
		String[][] di = 
	{{" 00000 ",
	 " 0     0",
	 " 0     0",
	 " 0     0",
	 " 0     0",
	 " 0     0",
	  " 00000 "},
	{"     1 ",
	"   1 1 ",
	"     1 ",
	"     1 ",
	"     1 ",
	"     1 ",
	"   1111"},
	{" 22222 ",
	"2     2",
	"      2",
	"     2 ",
	"   2   ",
	" 2    2",
	"2222222"},
	{" 33333 ",
	"3     3",
	"      3",
	"  3333 ",
	"      3",
	"3     3",
	" 33333 "},
	{"   44  ",
	"  4 4  ",
	" 4  4  ",
	"4   4  ",
	"4   4  ",
	"4444444",
	"    4  "},
	{" 55555 ",
	" 5     ",
	"555555 ",
	"      5",
	"      5",
	"5     5",
	" 55555 "},
	{" 6666  ",
	"6      ",
	"666666 ",
	"6     6",
	"6     6",
	"6     6",
	" 66666 "},
	{"7777777",
	"7    7 ",
	"    7  ",
	"   7   ",
	"  7    ",
	" 7     ",
	" 7     "},
	{" 88888 ",
	"8     8",
	"8     8",
	" 88888 ",
	"8     8",
	"8     8",
	" 88888 "},
	{" 99999 ",
	"9     9",
	"9     9",
	" 999999",
	"      9",
	"9     9",
	" 99999 "}};
		               
		char[] cc = (""+n).toCharArray(); 
		          
		for(int i=0; i<di[0].length; i++){
			for(int j=0; j<cc.length; j++){
				System.out.print( di[cc[j]-'0'][i]+ " ");  //填空位置
			}
			System.out.println();
		}	
	}
}

猜你喜欢

转载自blog.csdn.net/qq_42798905/article/details/87388109