【发布时间】:2015-12-22 02:50:07
【问题描述】:
我正在尝试编写一个示例程序来帮助我更好地理解 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 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
}
}
Eclipse 不会将任何错误标记为错误,并且在打印到控制台时我没有收到任何错误,只是我的第二行和第三行代码无论出于何种原因都不会在控制台上打印任何内容。我从文本中删除了一些单行和多行 cmets,但图片中的代码仍未编辑,感谢您的帮助,如果我的代码看起来令人困惑,我们深表歉意。
【问题讨论】:
-
对不起,我引用了任何图片,我试图包含来自 eclispe 的代码的一些图片,但网站不允许我包含我想要的数字,所以我只是删除了它们
-
您有一些额外的花括号,因此并非所有内容都是您的主要方法的一部分。
-
只有主方法内的 SOP 语句将被执行,根据您的代码,其他 SOP 语句不在主方法内,而是在实例块内。顺便说一句,代码将编译并运行良好。