0
[Edited] it's always printing wrong weather i type yes or no or anything
public class Program { public static void main(String[] args) { String answer; Scanner dec = new Scanner (System.in); answer = dec.next(); if (answer == "yes"){ System.out.println("right"); } else { System.out.println("wrong"); } } }
12 Réponses
+ 7
You can't use just next with the scanner. You have to say dec.nextInt() or dec.nextLine(); in your case.
+ 6
If it still isn't working then I suggest you post your code so that we can take a look at it, and maybe I can help you then, unless that is the entire code.
+ 3
I don't have any answers right now but I will continue looking.
+ 1
you need to use equals instead of ==
0
J.G. I don't know how to reply you but the code is working with dec.next();
0
the only problem now I'm facing is weather I type yes o r no or anything it's printing wrong. it should print right when I type yes
0
J.G. If you can tell me how to reply you lol I don't know how to reply
this is the entire code I just started learning java
0
Xin Xu not working
0
please post your code and your development environment…
0
Xin Xu this is the code :( and used eclipse
0
Did you import Scaner?
Import util.Scaner?
0
string cannot be compared with ==