public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("请字母:");
    String number = sc.next();

    if (number.equals("FE") || number.equals("fe")) {
        //字母F
        int[][] y = {{1, 1, 1, 0, 1, 1, 1}, {1, 0, 0, 0, 1, 0, 0}, {1, 1, 0, 0, 1, 1, 0}, {1, 0, 0, 0, 1, 0, 0}, {1, 0, 0, 0, 1, 1, 1}};
        int[] x = {};
        for (int i = 0; i < y.length; i++) {
            x = y[i];
            for (int j = 0; j < x.length; j++) {
                if (1 == x[j])
                    System.out.print("#");
                else
                    System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

输出结果如下图:

java代码使用坐标输出字母

代码中1表示输出“#”,0表示输出“ ”,数组{1, 1, 1, 0, 1, 1, 1}表示输出的是第一行的“### ###”;数组{1, 0, 0, 0, 1, 0, 0}表示输出的是第二行的“”#  #  ”;以此类推int[][] y数组中有多少数组表示有多少行,每个数组中有多少元素如{1, 1, 1, 0, 1, 1, 1},表示每行输出几个字符。此类方法可以用来打印直角三角形,等腰三角形等。

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2021-10-03
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-07-03
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2021-07-27
  • 2021-11-29
  • 2022-12-23
  • 2021-08-31
  • 2021-05-17
  • 2021-07-26
相关资源
相似解决方案