This question has already been answered:
- How to compare strings in java? 2 answers
I'm still completely green in java, when you enter male, Ms (Miss / Missis) + nickname is still displayed, although Mr. should be displayed.
package com.company.Start; import com.company.objects.Visitor; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner n = new Scanner(System.in); System.out.println("What's your name?"); String name = n.nextLine(); Scanner s = new Scanner(System.in); System.out.println("What's your sex(male/female)? "); String sex = s.next(); Random rnd = new Random(System.currentTimeMillis()); int cash = rnd.nextInt(3000); Visitor join = new Visitor(name, sex); String mrs; if (sex == "male") mrs = "Mr "; else mrs = "Ms "; System.out.println("Hello, Dear " + mrs + name); }
equalsmethod. - Regent