Java-我不能在同一行上打印(我没有使用println)

Java-我不能在同一行上打印(我没有使用println),java,Java,这似乎是一个常见的问题,但我找不到解决问题的方法。我最近才开始学习Java,所以我几乎不知道基本知识 我的教授布置了一个作业,我必须用星号写下我的名字。我只用了一个“System.out.print”就做到了这一点,而且非常混乱。所以我试了一下: public class teste2 { public static void main (String[] args) { String BR = "***** ***** \n* * * *\n* * *

这似乎是一个常见的问题,但我找不到解决问题的方法。我最近才开始学习Java,所以我几乎不知道基本知识

我的教授布置了一个作业,我必须用星号写下我的名字。我只用了一个“System.out.print”就做到了这一点,而且非常混乱。所以我试了一下:

public class teste2
{ public static void main (String[] args)
{ 
  String BR = "*****   ***** \n*    *  *     *\n*    *  *    *\n*****  *****  \n*     * *     *\n*     * *     *\n******  ";

  String U = "*     *\n*     *\n*     *\n*     *\n*     *\n*    *\n*******";

  System.out.print (BR + U);
}

它工作,但他们在不同的行,我需要它在只有一行。我做错了什么?

好的,正如您可能已经从对您的问题的评论中看到的,许多人说您使用“\n”来开始新的一行。所以要做到这一点,就像你必须一行接一行地写,所以为了做得更好,我首先要写所有的字母。为此,可以使用单个数组。 例如:


如果这没有帮助,对不起。但我会这样做,因为这很容易实现和使用。

嗯,字符串中确实有\n个字符。你知道那些是什么吗?是的,我需要它们来写这些信。我想是它们在起作用吗?\n是换行符的转义序列,意味着它在输出中放置了换行符。\n是换行符,打印时将光标移动到下一行。如果要将多个由星星组成的预制格式字符水平对齐,则不能这样做。这不是一个容易解决的问题。
public class teste2 {
     public static void main(String[] args) {
           // This creates T
           String[] t = new String[6];
           t[0] = "*******";
           for(int i = 1; i < t.length; i++) t[i] = "   *   ";

           // This creates E
           String[] e = new String[6];
           e[0] = "*******";
           e[1] = "*      ";
           e[2] = "****   ";
           e[3] = "*      ";
           e[4] = "*      ";
           e[5] = "*******";

           // This creates S
           String[] s = new String[6];
           s[0] = " ******";
           s[1] = "*      ";
           s[2] = " ***** ";
           s[3] = "      *";
           s[4] = "      *";
           s[5] = "****** ";

           // Now you need to print this.
           for(int i = 0; i < t.length; i++) {
                System.out.println(t[i]+"\t"+e[i]+"\t"+s[i]+"\t"+t[i]);
           }
           // This should be it.
           // You can still optimize the code and make everything in one
           // line but I think this is WAY better to read and better to
           // use as you can also use letters like the T more often.
           // BTW: this is TEST so not your name ;)
           // You need to program your own letters :)
     }
}