1. 程式人生 > >JAVA初學筆記---控制檯輸入:錯誤scanner

JAVA初學筆記---控制檯輸入:錯誤scanner

原始碼

——————

public class scanner
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a number in radius: ");
double radius = input.nextDouble();
double area = radius * radius * 3.14159;
System.out.println("The area for the cicle of radius " +
radius + "is " +area );
}
}

此項程式遇到的錯誤

——————

Exception in thread “main” java.lang.Error: Unresolved compilation problems:
Scanner cannot be resolved to a type
Scanner cannot be resolved to a type

at 從控制檯讀取.scanner.main(scanner.java:7)

解決方案

——————

*缺少
import java.util.Scanner ;
在第一行記入即可
因為Scanner屬於util包
所以需要匯入util包*