解题思路:
这题考察 switch, 按数字和行号区分图案即可
注意事项:
参考代码:
import java.util.Scanner; public class C1787 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); String num = String.valueOf(n); for(int i = 1; i <= 5; i++){ for(int j = 0; j < num.length()-1; j++){ System.out.printf("%s ", F(Integer.valueOf(""+num.charAt(j)), i)); } System.out.printf("%s\n", F(Integer.valueOf(""+num.charAt(num.length()-1)), i)); } } sc.close(); } private static String F(int num, int line){ switch(num){ case 0: if(line == 1 || line == 5) return "***"; else return "* *"; case 1: return " *"; case 2: if(line % 2 == 1) return "***"; else if(line == 2) return " *"; else return "* "; case 3: if(line % 2 == 1) return "***"; else return " *"; case 4: if(line < 3) return "* *"; else if(line == 3) return "***"; else return " *"; case 5: if(line % 2 == 1) return "***"; else if(line == 2) return "* "; else return " *"; case 6: if(line % 2 == 1) return "***"; else if(line == 2) return "* "; else return "* *"; case 7: if(line == 1) return "***"; else return " *"; case 8: if(line % 2 == 1) return "***"; else return "* *"; case 9: if(line % 2 == 1) return "***"; else if(line == 2) return "* *"; else return " *"; } return ""; } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:705 |
C二级辅导-分段函数 (C语言代码)浏览:912 |
小九九 (C语言代码)浏览:884 |
九宫重排 (C++代码)浏览:2194 |
printf基础练习2 (C语言代码)浏览:321 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1267 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:1322 |
简单的a+b (C语言代码)浏览:618 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:569 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1457 |