Cannot find the scanner

风格不统一 提交于 2019-12-24 11:40:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!