方法一:
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)); } } }