简体   繁体   English

System.out.print vs. System.out.println(最后一句)

[英]System.out.print vs. System.out.println (Last sentence)

I'm new to java and still have a lot of questions.我是java新手,还有很多问题。 Can someone explain to me why this:有人可以向我解释为什么会这样:

public class Programa02 {
  public static void main(String[] args ) {
       for (int lín = 1; lín <= 3; lín++) {
           for (int k = 0; k < (lín -1); k++) {
              System.out.print(" ");}
           
              System.out.print("\\");
              
           for (int m = 0; m < (6 - 2*lín); m++) {
              System.out.print(" ");}
           
              System.out.print("/");
              
             System.out.println(); }
              
       for (int lí = 1; lí <= 3; lí++) {
           for (int e = 0; e < (3 - lí); e++) {
              System.out.print(" ");}
           
              System.out.print("/");
              
           for (int i = 0; i < (2*lí - 2); i++) {
              System.out.print(" ");}
           
              System.out.println("\\");
}}}

works, but with this:有效,但有了这个:

System.out.print("\\");

at the end, doesn't?最后,不是吗? (look at the second-to-last line) (看倒数第二行)

BTW: I need it to show this:顺便说一句:我需要它来显示这个:

\    /
 \  /
  \/
  /\
 /  \
/    \

The only difference between println and print method is that println throws the cursor to the next line after printing the desired result whereas print method keeps the cursor on the same line. printlnprint方法之间的唯一区别是println在打印所需结果后将光标抛到下一行,而print方法将光标保持在同一行。

More information 更多信息

I wrote about it and have some examples at the following link:我写过它,并在以下链接中有一些示例:

https://creatingcoder.com/2020/08/07/println-vs-print/ https://creatingcoder.com/2020/08/07/println-vs-print/

Basically, the print method doesn't move the cursor, whereas the println creates a new line.基本上,print 方法不会移动光标,而 println 会创建一个新行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM