This question already has an answer here:
- How do I compare strings in Java? 23 answers
I am very new to java. I am wanting to combine 2 user inputs and output an answer using if statement. This is what I have so far and it just skips straight to the end. What am I doing wrong? And is there a better way of doing this?
import java.util.*;
class ifelse {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
String first_item;
System.out.print("Enter Item: ");
first_item = user_input.next();
String second_item;
System.out.print("Enter Item: ");
second_item = user_input.next();
String item_3;
item_3 = (first_item + " " + second_item);
if(item_3 == "blue yellow"){
System.out.println("green");
}
else if(item_3 == "yellow blue"){
System.out.println("green 3.0");
}
else{
System.out.println("your dumb");
}
}
}
Aucun commentaire:
Enregistrer un commentaire