【问题标题】:Drawing underscores upside down without unicode in Java [closed]在Java中没有unicode的情况下颠倒绘制下划线[关闭]
【发布时间】:2020-01-20 18:48:26
【问题描述】:

我想生成一个看起来像这样的图形(输出两行),其中图形的顶部是一个倒置的下划线:output

相反,它在同一行输出所有内容。我也不想使用UNICODE。

public class Landscape {

    String terrainString1;
    String terrainString2;

    Landscape(){
        terrainString1="";
        terrainString2="";
    }

    public void flat(int lengthOfFlatPortion){
        for (int count=0; count<lengthOfFlatPortion; count++){
            terrainString1+=" ";
            terrainString2+="_";
        }
    }
    public void hill(int lengthOfHillTop){
        terrainString1=" ";
        terrainString2="/";
        for (int count=0; count<lengthOfHillTop; count++){
            terrainString1+="_";
            terrainString2+=" ";
        }
        terrainString1+=" ";
        terrainString2+="\\";
    }

    public void print(){
        System.out.println(terrainString1);
        System.out.println(terrainString2);
    }

}

public class Main {
    public static void main(String[] args){
        Landscape landscape = new Landscape();

        landscape.flat(3);
        landscape.hill(5);
        landscape.flat(2);
        landscape.hill(3);
        landscape.flat(4);
        landscape.hill(0);
        landscape.flat(2);

        landscape.print();
    }
}

【问题讨论】:

  • hill 的前两行应该使用+= 而不是=
  • @tkausl Omg 多么愚蠢的错误谢谢

标签: java class oop


【解决方案1】:

我不知道这是否违反了您的“无 Unicode”要求,但 ASCII 238 中的“Macron”字符 (¯) 可以使用,具体取决于所选字体。

__/¯¯\__/¯\_     // This is a test of Macron character

否则,如果可以使用 Unicode,则有一个特定的“上划线”字符 ( ‾ ) (U+203E)。

__/‾‾\__/‾\_     // This is a test of overline character

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多