私は普段Eclipseが私にとって使いやすいのでプログラミングをしているのですが、先生の推薦がBlueJなんです。
先生がサンプルでコードを載せるときがあるのですが、importからscannerを使用しようと思ったのですが、BlueJではエラーは出ないのに、Eclipseではコンパイルエラーが出てしまいます。
こちらがコードです。
Eclipseを使ってる方で、なぜエラーが出てしまうのかわかる方いらっしゃいますか?
// this is required to use the Java library Scanner class import java.util.Scanner; /** * Keyboard input examples. Demonstrates how to use the Java library Scanner class * to read the different data types from keyboard input * * @author Anthony W. Smith * @version 5/31/2028 */ public class Scanning { /** * Start the Scanning example program */ public static void main(String args[]) { System.out.print("\f"); // clear the Terminal Window // create a new Scanner object named in and connect it to standard input and the keyboard Scanner in = new Scanner(System.in); // how to read an int System.out.print("Enter an int: "); int i = in.nextInt(); System.out.println("int was -->" + i + "<--"); // how to read a double System.out.print("Enter a double: "); double d = in.nextDouble(); System.out.println("Double was -->" + d + "<--"); // how to read a line in.nextLine(); // first discard contents of input buffer System.out.print("Enter some words: "); String line = in.nextLine(); System.out.println("Line was -->" + line + "<--"); // how to read a single word System.out.print("Enter some more words: "); String word = in.next(); System.out.println("First word was -->" + word + "<--"); System.out.println("Done"); in.close(); } }
あなたの回答
tips
プレビュー