- 2

How can i input yes or no in an if statement??

Ex: if(yes){print(let's play);}... this would b for Java..

2nd Nov 2016, 5:12 PM
jossafat corona
jossafat corona - avatar
3 Respostas
+ 1
For yes/no, you need to define a string variable. eg : myvar is a string variable String myvar="yes"; if(myvar=="yes") System.out.println("let us play"); else if(myvar=="no") System.out.println("let us code"); else System.out.println("Input is not valid");
2nd Nov 2016, 5:24 PM
Sumita Das
Sumita Das - avatar
0
Since one of his tags is boolean I think he want to do it with a boolean. Instead of string myvar="yes"; You can use this code: bool play = true; //some logic... If(play){ //do something } else { //do something }
2nd Nov 2016, 5:55 PM
Florian Schwarzer
0
so I have it your way Florian... I would lk for me to input(yes) rather than play..
2nd Nov 2016, 6:02 PM
jossafat corona
jossafat corona - avatar