我嘗試了每一個我知道的導入,並且它基本上一直給我使用鍵盤或數學的每一行上的類,接口或枚舉期望的錯誤。我應該使用什麼導入鍵盤掃描儀和數學?
如果你想知道的程序在做什麼,它假設找到2點之間的距離,使得用戶將英寸
// Sam
// 9.25.13
// import csl.Keyboard from the L: drive jdk
import java.io.*;
import java.util.*;
public class swagggg
public static void main (String [] args)
{
// declare variables
int x1, y1 ,x2, y2;
double distance;
// get user input
Scanner Keyboard = new Scanner (System.in);
System.out.println("Enter the first set of coordinates: ");
x1 = Keyboard.nextInt();
y1 = Keyboard.nextInt();
System.out.println("Enter the second set of coordinates: ");
x2 = Keyboard.nextInt();
y2 = Keyboard.nextInt();
// calculate using the Math class static method
distance = Math.sqrt(Math.pow(x2-x1,2) + (Math.pow(y2-y1,2));
// out results
System.out.println ("The distance between (" +x1+","+y1+") and ("+ x2 +","+y2+") is " + distance);
}
}
/
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 現在它編譯,但是當我在第一個座標類型,它看起來像這樣
Enter the first set of coordinates:
(2,9)
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at C2p8.main(C2p8.java:17)
Process completed.
雅,我沒有得到證明,因爲我找不到在標準庫中該死的導入。 – Sam
@同樣,'鍵盤'在JDK中不存在。它確實存在,因爲您的評論狀態'從L:驅動器jdk導入csl.Keyboard(這是爲學校電腦,不是我的)' –
@好吧,我添加了數學導入並將所有鍵盤掃描器更改爲java.util掃描器nextInt();它仍然不起作用 – Sam