问题
I have a very bad experienced about the scanner
because I am using GUI
and JOptionPane
. So I am not be able to do the program's interns of scanner
because. I am new to it so Please help me, "cannot find the scanner
". This is my code so far .
import java.io.*;
import java.util.*;
class MultiplicationTables{
public static void main(String args[]){
int n, c;
System.out.println("Enter an integer to print its multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of "+n+" is :-");
for ( c = 1 ; c <= 10 ; c++ )
System.out.println(n+"*"+c+" = "+(n*c));
}
}
回答1:
If your Java is not version 1.5 or above, Scanner class is not provided.
go to command promt
type "java -version"
check your version.If you have outdated just update. Problem shoud be fixed.. and make sure your IDE or the JDK actually use it.
Code that you have here provided is correct so you can use it after you fix your problem.
回答2:
First import is redundant.
import java.io.*; // you can remove it
Scanner is a class in java.util package. Check weather you have properly set your jdk path in your ide, or in your system. Depends on system that you use: Windows: Advanced System Settings->Environment Variables->Path check weather there is your path to jdk.
UNIX in console print 'echo $PATCH' and check that if you have there jdk path properly added.
And then you can check your version of java independent to system in console writing
java --version
来源:https://stackoverflow.com/questions/22068618/cannot-find-the-scanner