蓝桥杯基础练习——字母图形

两段Java代码分别展示了不完全和完全正确通过(AC)的字母图形打印。第一段代码使用字符数组存储字母并进行打印,第二段代码通过计算绝对值与'A'的和来生成图形。两段代码均根据输入的行数(n)和列数(m)输出相应的字母矩阵。
摘要由CSDN通过智能技术生成

在这里插入图片描述
在这里插入图片描述
我的不完全AC代码

package 蓝桥基础;
import java.util.Scanner;
public class 字母图形1 {
	public static void main(String []args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		char[] str = new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
		//虽然我知道这样存数很low,并且存完之后就想到了ASCII
		int s = str.length;
		
		for(int i = 0; i < n; i++) {	
			for(int l = i+1; l>0; l--) {
				System.out.print(str[l-1]);	
			}	
			for(int k = 1; k < m; k++) {
				System.out.print(str[k]);
			}
			m--;
			System.out.println();
		}
	}
}

完全AC代码

package 蓝桥基础;
import java.util.Scanner;
public class 字母图形2 {
	
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();//行数
			int m = sc.nextInt();//列数
			for(int i = 0 ; i < n; i++) {
				for(int j = 0 ; j < m ;j++) {
					char c = (char)(Math.abs(i - j) + 'A');
					System.out.print(c);
				}
				System.out.println();
			}
		}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值