我是新来的这个网站,我想写一个示例程序来帮助我更好地理解java,但问题是Eclispe只会打印出任何内容对于一行代码而言并非全部都是System.out.println()
。eclispe不会打印多行代码到控制台
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
}
}
Eclispe的不会标记任何东西作为错了,我没有得到任何错误打印到它的控制台时只是我的代码打印什么二,三线控制台无论出于何种原因。我从文本中删除了一些单行和多行的注释,但代码在图片中保持未编辑状态,感谢您的帮助,如果我的代码看起来很混乱,我会很抱歉。
对不起,我参考了任何图片,我试图包括eclispe的代码的一些图片,但网站不会让我包括我想要的数字,所以我只是删除它们 – Ronaldo
你有一些额外的花括号,所以不是所有是你主要方法的一部分。 –
只有主方法内部的SOP语句会被执行,因为根据你的代码,其他SOP语句不在主方法内部,而是在实例块内部。顺便说一句代码将编译和运行良好。 – user0946076422