class Hi {
public static void main(String []args){
if(args.length ==0)
System.out.println("Hello World!");
else
System.out.println("Hello ");
for(int i = 0; i < args.length; i++){
System.out.println(args[i] + " ");
}
}
}
嗨,我有一个非常简单的程序。如果我像这样运行它:java嗨Robin Hood 我希望得到一条只有1行的输出:
Hello Robin Hood
但相反,我得到了:
您好
罗宾
遮光罩
任何人都可以教我如何制作所需的输出?谢谢
答案 0 :(得分:2)
使用
System.out.print("Hello ");
和
System.out.print(args[i] + " ");
循环中的
答案 1 :(得分:2)
System.out.print("This is on ");
System.out.println("one line.");
System.out.print("This is the ");
System.out.println("next line.");
输出:
This is on one line.
This is on the next line.
祝你好运! :)