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

问题描述
利用字母可以组成一些美丽的图形,下面给出了一个例子:

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

这是一个5行7列的图形,请找出这个图形的规律,并输出一个n行m列的图形。
代码如下;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String[] sarr=sc.nextLine().split(" ");
int n=Integer.parseInt(sarr[0]);
int m=Integer.parseInt(sarr[1]);
StringBuffer str=new StringBuffer();
if(m<=26&&n<=26) {//我这个n如果大于26会报错…
int[] words=new int[26];
int index=0;
for(int i=65;i<65+26;i++) {
words[index++]=i;
}
for(int i=0;i<n;i++) {
if(i==0) {
for(int j=0;j<m;j++) {
str.append((char)words[j]);
}
System.out.println(str);
str.delete(0, m);
}else if(i<m){
int currentI=i;
for(int j=currentI;j>0;j–) {
str.append((char)words[j]);
}
for(int j=0;j<m-currentI;j++) {
str.append((char)words[j]);
}
System.out.println(str);
str.delete(0, m);
}else {
int count=m;
int currentI=i;
while(count>0) {
str.append((char)words[currentI–]);
count–;
}
System.out.println(str);
str.delete(0, m);
}
}
}
}
}

本人新手纯属瞎写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值