嘿,我刚刚开始我的第一本关于java的编程书籍,所以这应该是一个简单的修复。玩弄我对条件句的新知识,我得到了标题错误。
代码如下:
import java.util.Scanner;
public class Music
{
public static void main( String[] args )
{
Scanner x = new Scanner( System.in );
int y;
System.out.print( "Which is better, rap or metal? 1 for rap, 2 for metal, 3 for neither" );
y = input.nextInt();
if ( y == 1 )
System.out.print( "Someone hasn't heard\nhttp://www.youtube.com/watch?v=Vzbc4mxm430\nyet" );
if ( y == 2 )
System.out.print( "Someone hasn't heard\nhttp://www.youtube.com/watch?v=s4l7bmTJ7j8\nyet" );
if ( y == 3 )
System.out.print( "=/ \nMusic sucks anyway." );
}
}
当我尝试编译时:
Music.java:13: error: cannot find symbol
y = input.nextInt();
symbol: variable input
location: class Music
1 error
发布于 2012-09-02 23:31:43
错误消息告诉您变量'input‘不存在于您的作用域中。您可能希望使用Scanner对象,但您将其命名为'x',而不是'input‘。
Scanner input = new Scanner( System.in );
应该能修好它。
发布于 2012-09-02 23:31:52
您还没有在这里定义变量input
。你应该有:
Scanner input = new Scanner( System.in );
发布于 2012-09-02 23:33:52
您使用了变量输入,如下所示
y=input.nextInt();
你不能这样做,因为它不是一个变量。我相信你的意思是它应该是"x",或者你可以用
Scanner x = new Scanner( System.in );
使用
Scanner input = new Scanner( System.in );
https://stackoverflow.com/questions/12237209
复制相似问题