0

I'm having trouble writing a program that will give me a YES or NO message given the input I enter for my robot. I want to enter my wheel configuration (doesn't matter what it is), and I want the output to show YES if it can move with the wheel configuration I enter.

Thus far, I have this basic code:

 If(a=="yes"){
        System.out.println("YES");
    }
    else if(a == "no"){
        System.out.println("NO");

Notice how I've not added numbers into the bracket because I'm not sure how to approach this, and it's the first time I'm really testing myself - and I'm new to Java. Help is appreciated as ever.

Hectic
  • 61
  • 1
  • 6

2 Answers2

1

Try to change == with equals

if(a.equals("yes")){
    System.out.println("YES");
}
else if(a.equals("no")){
    System.out.println("NO");
MSA
  • 2,502
  • 2
  • 22
  • 35
1

Because you are comparing Strings you should use equals() since that only compares what was written. == however only returns True if it refers to the same Object.

Do as following:

if(a.equals("yes"))
   System.out.println("YES");
else if(a.equals("no"))
   System.out.println("NO");
Frunk
  • 180
  • 1
  • 2
  • 11