英文:
System.out.print vs. System.out.println (Last sentence)
问题
我是新手Java,还有很多问题。
有人能解释一下为什么这段代码可以工作,但加上这行:
System.out.print("\\");
在结尾的时候却不能工作吗?(看倒数第二行)
顺便说一句:我需要它显示这样:
\ /
\ /
\/
/\
/ \
/ \
英文:
I'm new to java and still have a lot of questions.
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:
\ /
\ /
\/
/\
/ \
/ \
答案1
得分: 1
println
和print
方法之间唯一的区别在于,在打印所需结果后,println
会将光标移动到下一行,而print
方法会保持光标在同一行上。
英文:
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.
答案2
得分: 0
我写了关于这个的内容,并在以下链接中提供了一些示例:
https://creatingcoder.com/2020/08/07/println-vs-print/
基本上,print方法不会移动光标,而println会创建新的一行。
英文:
I wrote about it and have some examples at the following link:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论