打印三角型字母

/** 输入一个大写字母,如F 比如: 输入:F 输出: A ABA ABCBA ABCDCBA ABCDEDCBA ABCDEFEDCBA输入:C 输出: A ABA ABCBA*/ import java.util.Scanner; class Work17Letter { public static void main(String[] args) { System.out.println(""); Scanner sc=new Scanner(System.in); String str=sc.nextLine(); char ch=str.charAt(0); int a=(int)ch; if (a<65||a>90) { System.out.println("超出范围"); return; } for (int i=65; i<=a ; i++ ) { for (int n=65; n<=i ; n++ ) { System.out.print((char)n); } for (int m=i-1; m>=65 ; m-- ) { System.out.print((char)m); } System.out.println(""); } } } /** 输入一个大写字母,如 F,输出 比如: 输入:F 输出: F EFE DEFED CDEFEDC BCDEFEDCB ABCDEFEDCBA 输入:D 输出: D CDC BCDCB ABCDCBA*/ import java.util.Scanner; classWork18Letter { public static void main(String[] args) { System.out.println("请输入一个大写字母:"); Scanner sc=new Scanner(System.in); String str=sc.nextLine(); char ch=str.charAt(0); int x=(int)ch; if (x<65||x>90) { System.out.println("超出范围"); return; } for (int i=x ; i>=65 ; i-- )//循环行数 {for (int n=x-i; n>=0 ; n-- )//先输出X前的字母, { System.out.print((char)(x-n)); } for (int m=1; m<=x-i ; m++ ) { System.out.print((char)(x-m)); } System.out.println(""); } } }


    推荐阅读