3
public class TemperatureChanger
{
    public static void main(String[]args)
    {
        Scanner keyboard = new Scanner(System.in);

        int c;
        int f;
        int tempFaren;

        System.out.println("Enter temperature in celcius");
        c = keyboard.nextInt();
        tempFaren = (9 *c)/5 + 32;

        System.out.println( " In Fahrenheit that is " + tempFaren );
    }
}

TemperatureChanger.java:7: cannot find symbol Scanner keyboard = new Scanner(System.in)在编译期间收到错误。我需要做什么来解决这个问题。

4

2 回答 2

3

您需要import java.util.Scanner;或 Java 不会找到Scanner该类。另一种可能性是使用类的完整路径,但现在这样做似乎不太实用。

于 2013-04-27T01:11:00.757 回答
0

使用前需要先导入 Scanner:

Scanner keyboard = new Scanner(System.in);

另外我不知道你是否忘记粘贴它,但你还必须给你的班级起个名字。例如:

public class Change {
}
于 2013-04-27T01:11:20.213 回答