+ 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
7 Respostas
+ 1
Scanner obj=new
Scanner(System.in);
System.out.println("u entered");
System.out.println(n=obj.nextInt());
+ 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);
+ 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 :)
+ 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.
+ 1
3 great answers Aquarius, sachin and jai thank you
+ 1
ur most welcome sushmitha