Java编译错误:找不到符号 [英] Java compile error: cannot find symbol

查看:1115
本文介绍了Java编译错误:找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我刚刚开始我的第一本关于java的编程书,所以这应该是一个容易修复。

Hey I'm just starting my first programming book on java so this should be an easy fix. Messing around with my fresh knowledge of conditionals and I'm getting the title error.

这是代码:

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


推荐答案

错误消息告诉您,您的变量输入不存在于您的作用域中。您可能想要使用Scanner对象,但是将其命名为x,而不是input。

The error message is telling you that your variable 'input' doesn't exist in your scope. You probably want to use your Scanner object, but you named it 'x', not 'input'.

Scanner input = new Scanner( System.in );

应修复它。

这篇关于Java编译错误:找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆