简体   繁体   English

netbeans 12.0 打印和打印

[英]netbeans 12.0 print and println

Our university chooses netbeans IDE in our OOP java, my question is why did it not print System.out.print("Input number: "); Our university chooses netbeans IDE in our OOP java, my question is why did it not print System.out.print("Input number: "); first in this code snippet首先在此代码段中

public class Main {
    public static void main (String[] args){    
      Scanner scan= new Scanner(System.in);    
        System.out.print("Input number: ");
        int num = scan.nextInt();
        System.out.println("number inputted is " + num);
    }
}

here is the output output1这是output 输出1

but when I change the line to System.out.println this is the output output2但是当我将行更改为System.out.println这是 output output2

is this some netbeans stuff?这是一些 netbeans 的东西吗?

It is running absolutely fine in my netbeans.它在我的 netbeans 中运行得非常好。 Re install it there might be any changes at the time of installation Now if you are beginner you can practice java in bluej.重新安装它安装时可能会有任何变化现在如果你是初学者,你可以在bluej中练习java。

If you want the stuff "number inputted is n" in the next line, then add println to the 4th line of your program.如果您想在下一行中显示“输入的数字为 n”的内容,则将 println 添加到程序的第 4 行。 This is your required code:这是您需要的代码:

    public class Main {
        public static void main (String[] args){    
          Scanner scan= new Scanner(System.in);    
            System.out.println("Input number: ");
            int num = scan.nextInt();
            System.out.println("number inputted is " + num);
        }
    }

NOTE: We use println to make the cursor move down, to the next line after the text is printed.注意:我们使用 println 使 cursor 下移到打印文本后的下一行。 For eg.-例如-

public class Main {
            public static void main (String[] args){      
                System.out.print("Input number:);
                System.out.println("number inputted is " );
            }
        }

prints: Input number:number inputted is打印:输入数字:输入的数字是

What the above code does is that it also shifts the cursor down to the next line in the terminal, so that the next line you print is printed in the next line.上面的代码所做的是它还将 cursor 向下移动到终端中的下一行,以便您打印的下一行打印在下一行中。 but,但,

public class Main {
                public static void main (String[] args){      
                    System.out.println("Input number:);
                    System.out.print("number inputted is " );
                }
            }

this prints: Input number: number inputted is这打印:输入数字:输入的数字是

I hope it is clear to you!!我希望你清楚!!

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

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