KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I just started Java programming. I love it so far, but I have been stuck on this problem for a while. When I run this code, whenever I type in “boy” it will just respond with GIRL : import java.util.Scanner; public class ifstatementgirlorboy { public static void main(String args[]) { System.out.println("Are you a boy or a girl?"); Scanner input = new Scanner(System.in); String gender = input.nextLine(); if(gender=="boy") { System.out.println("BOY"); } else { System.out.println("GIRL"); } } } Why?
Tags (comma-separated)
Save Edits
Cancel