Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
X不能解析为for循环中的变量;Eclipse,Java_Java_Eclipse_For Loop_Int - Fatal编程技术网

X不能解析为for循环中的变量;Eclipse,Java

X不能解析为for循环中的变量;Eclipse,Java,java,eclipse,for-loop,int,Java,Eclipse,For Loop,Int,我刚刚开始使用Java,我遇到了一个错误,对此我不理解。我已经看过了,在另一个问题中找不到我的答案,如果这是重复的话,我很抱歉 我的代码是: public class Welcome { public static void main(String[] args) { System.out.println("x\t x^2\t x^3"); for(int x = 1; x < 5; x++) System.out.println(x); S

我刚刚开始使用Java,我遇到了一个错误,对此我不理解。我已经看过了,在另一个问题中找不到我的答案,如果这是重复的话,我很抱歉

我的代码是:

public class Welcome {
public static void main(String[] args) {
    System.out.println("x\t x^2\t x^3");
    for(int x = 1; x < 5; x++)
        System.out.println(x);
        System.out.println("\t");
        System.out.println(x * x);
        System.out.println("\t");
        System.out.println(x * x * x);
    }
}
公共课欢迎{
公共静态void main(字符串[]args){
System.out.println(“x\t x^2\t x^3”);
对于(int x=1;x<5;x++)
系统输出println(x);
System.out.println(“\t”);
System.out.println(x*x);
System.out.println(“\t”);
System.out.println(x*x*x);
}
}
对于第一次打印,代码将通过
x
正常运行,但在随后的行中,
x*x
x*x*x
的行为类似于未定义
x
。我怎样才能运行这段代码?我的错误背后的原因是什么


谢谢。

你忘了把if的范围放在这里

只有在未指定开始和结束花括号时,才会运行第一个println

for(int x = 1; x < 5; x++)
{
    System.out.println(x);
    System.out.println("\t");
    System.out.println(x * x);
    System.out.println("\t");
    System.out.println(x * x * x);
}
for(int x=1;x<5;x++)
{
系统输出println(x);
System.out.println(“\t”);
System.out.println(x*x);
System.out.println(“\t”);
System.out.println(x*x*x);
}
你是代码

for(int x = 1; x < 5; x++)    
    System.out.println(x);        //if you didn't specified the begin and end curly brace 
                                  //for range . this is the only line will work for it
    System.out.println("\t");     //from this line, x now is undefined
    System.out.println(x * x);    //*
    System.out.println("\t");     //*
    System.out.println(x * x * x);//until here
for(int x=1;x<5;x++)
系统输出println(x)//如果未指定开始和结束大括号
//射程。这是唯一一条适合它的线路
System.out.println(“\t”)//从这一行开始,x现在是未定义的
System.out.println(x*x)//*
System.out.println(“\t”)//*
System.out.println(x*x*x)//直到这里

为(int x=1;x<5;x++){的
添加一个开始大括号,并在
System.out.println(x*x*x);}之后添加一个结束大括号
ahhhh,谢谢:)