2个回答
展开全部
//修改n的值,可以是1到26或更大也可以:
public class Print {
static int n = 26;
static char c = 'A';
static char[][] arr = new char[n][];
static int num = 1;
public static void main(String[] args) {
for (int i = 1; i < arr.length; i++) {
num += 2;
}
arr = new char[n][num];
int space = num / 2;
for (int i = 0; i < n; i++) {
arr[i][space] = c ++;
char d = (char)(c - 1);
leftPrint(space, d, i);
rightPrint(space, d, i);
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if ( arr[i][j] == '\0')
System.out.print(" ");
else
System.out.print(arr[i][j]);
}
System.out.println();
}
}
public static void leftPrint(int space, char d, int i) {
for (int j = 0; j < i; j++) {
arr[i][--space] = --d;
}
}
public static void rightPrint(int space, char d, int i) {
for (int j = 0; j < i; j++) {
arr[i][++space] = --d;
}
}
}
public class Print {
static int n = 26;
static char c = 'A';
static char[][] arr = new char[n][];
static int num = 1;
public static void main(String[] args) {
for (int i = 1; i < arr.length; i++) {
num += 2;
}
arr = new char[n][num];
int space = num / 2;
for (int i = 0; i < n; i++) {
arr[i][space] = c ++;
char d = (char)(c - 1);
leftPrint(space, d, i);
rightPrint(space, d, i);
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if ( arr[i][j] == '\0')
System.out.print(" ");
else
System.out.print(arr[i][j]);
}
System.out.println();
}
}
public static void leftPrint(int space, char d, int i) {
for (int j = 0; j < i; j++) {
arr[i][--space] = --d;
}
}
public static void rightPrint(int space, char d, int i) {
for (int j = 0; j < i; j++) {
arr[i][++space] = --d;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Guess {
//
参数1: 你需要的行数 参数2:首字母
static public void printX(int row,char beginChar)
{
for(int i=1;i<=row;i++)
{
for(int j=1;j<row*2;j++)
{
if(j>row+i-1 || j<row-i+1) System.out.print(" ");
else {
if(j<row) System.out.print((char)((int)beginChar+i-1-(row-j)));
else if(j>row) System.out.print((char)((int)beginChar+i-1+(row-j)));
else System.out.print((char)((int)beginChar+i-1));
}
}
System.out.println();
}
}
static public void main(String[] sss){
printX(11,'A');
}
}
一个static函数
//
参数1: 你需要的行数 参数2:首字母
static public void printX(int row,char beginChar)
{
for(int i=1;i<=row;i++)
{
for(int j=1;j<row*2;j++)
{
if(j>row+i-1 || j<row-i+1) System.out.print(" ");
else {
if(j<row) System.out.print((char)((int)beginChar+i-1-(row-j)));
else if(j>row) System.out.print((char)((int)beginChar+i-1+(row-j)));
else System.out.print((char)((int)beginChar+i-1));
}
}
System.out.println();
}
}
static public void main(String[] sss){
printX(11,'A');
}
}
一个static函数
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询