我正在嘗試使用基本掃描儀使用https://www.compilejava.net/。下面是代碼:導入掃描儀聯機IDE
import java.lang.Math;
import java.util.Scanner;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Gimmie a value");
Scanner scan = new Scanner(System.in);
int v1 = scan.nextInt();
System.out.println(v1);
}
}
這是輸出:
Gimmie a value
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at HelloWorld.main(HelloWorld.java:29)
什麼是輸入? – Jens
如果你想讓你的程序讀取一個int,你應該在按下「intro」之前寫出一個int – SJuan76