Java Why is StdIn.java Not Working in My Program?

  • Thread starter Thread starter Hiche
  • Start date Start date
  • Tags Tags
    Program
Click For Summary
Using StdIn and StdOut in a program can lead to issues if the necessary files are not correctly set up. The StdIn.java file should be placed in the same directory as the source file. If errors occur, such as "StdIn cannot be resolved," it may indicate a missing import statement. However, in Eclipse, if both files are in the same directory (typically the src folder), the import statement may not be necessary. Refreshing the project can resolve recognition issues, allowing the program to compile and run correctly.
Hiche
Messages
82
Reaction score
0
I want to use StdIn and StdOut in my program as instructed. Our teacher told us to put the StdIn.java file inside the same folder as the source file (the program I am writing). But that is not working. Always gives me an error when I use the commands.

Am I doing it wrong? Is there another way?

Code:
StdOut.print or StdIn.readIn()
(for example)
 
Technology news on Phys.org
I think you might be missing an import statement at the top of your code. It would look like this:
Code:
import StdIn;
// any other imports
.
.
.
<your code>
 
I added the import statement but the error keeps appearing: "StdIn cannot be resolved". I'm positive that I placed the StdIn.java file in the same directory as my program. I am using Eclipse as an IDE so the .java files are usually in a folder called src, where I also put the StdIn.java.
 
Never mind. I just had to refresh my project. The import statement is not really needed when we place the .java files in the same directory.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
1K
Replies
14
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 12 ·
Replies
12
Views
11K
Replies
7
Views
1K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K