Simple input scanner import error

There is some problem in the import statement. We are supposed to use scanner for taking user input here, right?

Please share your code using ide.codingblocks.com so that I can help you better. Yes, scanner class is used to take input from user, what problem are you facing exactly?

The collaboration mode is on. Should I copy paste the code here as well?

No, that’s alright. Your code is correct, why have you added the C++ code in the beginning? Please remove that. You might be getting an error if you did not give sample input in the input box. You need to paste the sample input there and then run your code. Let me know if you’re still facing an issue

The c++ code must have gotten added by misteake.

It is still showing the same import error

When I ran your code, it ran perfectly. Can you copy paste the error message here? I think you have not changed the language of the ide. You are running java code in c++ ide, please change the language from dropdown menu above

Compiling failed with exitcode 1, compiler output: prog.cpp:1:1: error: ‘import’ does not name a type; did you mean ‘short’? import java.util.*; ^~~~~~ short prog.cpp:2:1: error: expected unqualified-id before ‘public’ public class Main { ^~~~~~

The error is due to what I mentioned above. Change your ide language to java, you are currently running it using c++ compiler. There is a language menu just beside the Run button, change language from there

It worked now, thanks

1 Like