Jump to content

java question

digitalMaster

Hello guys

im a starter at java and i wanna ask you something

How can i ask from the user to type some integers or strings or whatever from keyboard??

till now i can do this but im not sure.

1)make a class with objects and constructors and methods

2)some of my methods are getSomething(int Something);    and   setSomething(int Something)

 

in this may i can use my main which is in another class of my project to type some strings but im not sure if its the answear

if the user is a absolutely stranger with java??

he will be able to type throught main??i dont think so

Link to comment
Share on other sites

Link to post
Share on other sites

You're gonna have to take a look at the Scanner class.

 

Scanner input = new Scanner(System.in);

String name = input.next();

ty man

Link to comment
Share on other sites

Link to post
Share on other sites

There are many ways of doing this, the most efficient current way would be to retrieve the console input with System.console().readLine(); Keep in mind that this only works when running the app through the command line so it won't work within most IDEs. Just export it and use the java -jar filename.jar command to run it instead

Link to comment
Share on other sites

Link to post
Share on other sites

Make sure you import javax.swing.JOptionPane;

 

String Varaiable = JOptionPane.showInputDialog(null, "Question Here", "JPane Title here");

 

Change Variable to whatever you want it to be

"Do not pray for and easy life, pray for the strength to endure a difficult one."

 

"A place where everything and nothing exists, this is my playground."

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×