[试题 基础练习 字母图形]字符的二维数组的运用

 

 方法一:

import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {
   public static void main(String [] args) {
     Scanner sc = new Scanner(System.in);
     int n = sc.nextInt();
     int m = sc.nextInt();
     sc.close();
     char[][] a=new char[n][m];
     if(n>=1&&m<=26)
    for(int i=0;i<n;i++) {
       for(int j=0;j<m;j++){
          if(j==i) a[i][j] = (char)('A'+0);
          else a[i][j] = (char)('A'+Math.abs(i-j));///
          System.out.print(a[i][j]);
       }
      System.out.println();
    }
   }
}

  

方法二:

import java.util.*;

public class Main {
   public static void main(String [] args) {
     Scanner sc = new Scanner(System.in);
     int n = sc.nextInt();
     int m = sc.nextInt();
     sc.close();
    String str="ZYXWVUTSRQPONMLKJIHGFEDCBABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i=0;i<n;i++){
       System.out.println(str.substring(25-i,25-i+m));
    }
   }
}

  

posted @ 2020-03-28 09:20  wusheng_z  阅读(245)  评论(0编辑  收藏  举报