首页 > 解决方案 > Java - 输出行

问题描述

我想知道是否有办法在运行后在输出中创建一行,

代码是

int topScore = 80;
        if (topScore < 100) {
            System.out.println("You got the high score!");
        }
        int secondTopScore = 60;
        if (topScore > secondTopScore && topScore < 100) {
            System.out.println("Greater than second top score and less than 100");
        }

        //Video 36 - Logical OR Operator

        int topScore1 = 80;
        if (topScore1 < 100) {
            System.out.println("You got the high score!");
        }
        int secondTopScore1 = 81;
        if ((topScore1 > secondTopScore1) && (topScore1 < 100)) {
            System.out.println("Greater than second top score and less than 100");
        }

输出是

   You got the high score!
   Greater than second top score and less than 100
   You got the high score!

但是我希望它有一个空格链接这个

You got the high score!
Greater than second top score and less than 100
**Blank Line
You got the high score!

我试过 \n 但似乎没有用

标签: java

解决方案


您可以添加\n到字符串的开头

  int topScore = 80;
    if (topScore < 100) {
        System.out.println("\nYou got the high score!");
    }
    int secondTopScore = 60;
    if (topScore > secondTopScore && topScore < 100) {
        System.out.println("Greater than second top score and less than 100");
    }

    //Video 36 - Logical OR Operator

    int topScore1 = 80;
    if (topScore1 < 100) {
        System.out.println("\nYou got the high score!");
    }
    int secondTopScore1 = 81;
    if ((topScore1 > secondTopScore1) && (topScore1 < 100)) {
        System.out.println("Greater than second top score and less than 100");
    }

推荐阅读