Java 日食赢了';t在控制台上打印多行代码
我试图编写一个示例程序来帮助我更好地理解java,但问题是Eclipse只会打印出Java 日食赢了';t在控制台上打印多行代码,java,string,int,Java,String,Int,我试图编写一个示例程序来帮助我更好地理解java,但问题是Eclipse只会打印出System.out.println()中的一行代码,而不是全部代码 class MyClass { public static void main(String[] args){ System.out.println("I am learning Java"); System.out.println("Hello World"); String
System.out.println()
中的一行代码,而不是全部代码
class MyClass {
public static void main(String[] args){
System.out.println("I am learning Java");
System.out.println("Hello World");
String fruit = "apple";
int sea =1;
double goaldifference = 2.54;
System.out.println(fruit);
System.out.println(sea);
System.out.println(goaldifference);
} //this line of code is printed to the console
{
int a , b , c;
a =4;
b =6;
c = a+b;
System.out.println(c);
int hen =17;
System.out.println(++hen);
}//this line of code isn't printed to the console
{
int test = 6;
if (test == 9){
System.out.println("yes");
}else{
System.out.println("no");
if (test != 8){
System.out.println("no");
}else{
System.out.println("try different number");
}
int age = 14;
if(age < 16){
System.out.println("still in high school");
}else if (age > 16){
System.out.println("in college");
}//this line of code isn't printed to the console
}
}
class-MyClass{
公共静态void main(字符串[]args){
System.out.println(“我正在学习Java”);
System.out.println(“你好世界”);
串果=“苹果”;
int sea=1;
双目标差=2.54;
系统输出打印(水果);
系统输出打印(sea);
系统输出打印LN(目标差异);
}//这行代码被打印到控制台
{
INTA、b、c;
a=4;
b=6;
c=a+b;
系统输出打印ln(c);
int-hen=17;
System.out.println(++hen);
}//这行代码没有打印到控制台
{
int检验=6;
如果(测试==9){
System.out.println(“是”);
}否则{
系统输出打印项次(“否”);
如果(测试!=8){
系统输出打印项次(“否”);
}否则{
System.out.println(“尝试不同的号码”);
}
年龄=14岁;
if(年龄<16岁){
System.out.println(“仍在读高中”);
}否则,如果(年龄>16岁){
System.out.println(“学院内”);
}//这行代码没有打印到控制台
}
}
Eclipse不会将任何内容标记为错误,并且在打印到控制台时也不会出现任何错误。只是我的第二行和第三行代码出于任何原因都不会打印到控制台。我从文本中删除了一些单行和多行注释,但代码在图片中仍然未编辑谢谢帮助,如果我的code看起来很混乱。在完成消息后,只需使用
\n
。例如:
System.out.println("First line\n");
System.out.println("Next line\n");
\n
是一个特殊的字符。每当你看到带字符的前导反斜杠时,表示它做了一些特殊的事情。\n
表示转到下一行。对不起,我参考了任何图片,我试图从eclispe中包含一些代码图片,但网站不允许我包含我想要的号码o我刚刚删除了它们。您有一些额外的大括号,因此并非所有内容都是主方法的一部分。根据您的代码,将只执行主方法中的SOP语句,其他SOP语句不在主方法中,而是在实例块中。顺便说一句,代码将编译并运行良好。System.out.println();
它本身有\n
可以请更详细地解释在哪里使用System.out.println(“第一行”;“System.out.println(“下一行”\n”);在我的代码中,请查看Bahramdun的答案链接。它详细介绍了如何找到解决方案。正如我所说的,该链接不起作用,我对System.out.println(“第一行”;“System.out.println”(“下一行”\n))的位置感到困惑可以在任何地方使用。无论您将System.out.println()
放在何处,您都可以向其中添加\n
添加新行。