Skip to content
Advertisement

Print user inputs from 2D array using another class in Java?

I am trying to print user inputs in another class in Java. I have made a chessboard which asks the user to input strings on the board, and then, when these strings are printed on screen, I would like the output to be “You have placed piece [name] at coordinate [coordinate]”. I am trying to do this in another class rather in the main method, but what I have tried so far doesn’t seem to work. Here’s my code.

JavaScript

So what I’d like to do is have a new class that uses that last print line to instead print the desired output that I mentioned earlier. Any help would be appreciated, thanks!

EDIT:

JavaScript

I have 2 separate files userInputs and showInput but they it says that they should still be declared in a separate file?

Advertisement

Answer

It’s wrong to write main Function in every class, the program uses the main function to start from it, So you should write it only in the main project class and call inside it the other classes. Your code should be:

JavaScript

and other classes in separate files like:

JavaScript

and another class to output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement