+ 1

how to give inputs

I want my program to take values that I will enter what key words do I use how do I create a program which takes the values that I enter

5th Aug 2016, 6:48 PM
sushmitha
sushmitha - avatar
6 Respostas
+ 1
Scanner obj=new Scanner(System.in); System.out.println("u entered"); System.out.println(n=obj.nextInt());
5th Aug 2016, 6:59 PM
jai
+ 1
here I can't tell whole scenario you can take input from user by using BufferedReader class and Scanner class BufferedReader br=new BufferedReader (new InputStreamReader(system.in)); sop ("enter a number"); int n=Integer.parseInt (br.readline ()); sop (n);
5th Aug 2016, 7:20 PM
sachin tomar
sachin tomar - avatar
+ 1
what do you mean? like how to let the user interact with your program if so th code is: playerAnswer = scan.nextLine (); im sure you know about if, else, and else if statements so just do that for your users options. and if your doing a console game and want to make sure the user can only type one of the options, put that code and the other statements within a while loop thats set to true. the reason why you should do this is because if for example you have two options apple and pear and the player says orange. if you put a message in there some where saying "sorry, answer not recognized" it will say that message and repeat the question. hope that helped :)
5th Aug 2016, 8:24 PM
Aquarius
Aquarius - avatar
+ 1
actually an excellent question/topic! A lot of code thats kind of boring or one-dimensional gets a lot more interesting when you replace a constant (20 mpg) with user input ("how many mpg go you get?") Scanner is great for this.
5th Aug 2016, 10:09 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
+ 1
3 great answers Aquarius, sachin and jai thank you
5th Aug 2016, 10:11 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
+ 1
ur most welcome sushmitha
6th Aug 2016, 1:15 AM
sachin tomar
sachin tomar - avatar