slashjack Posted October 19, 2011 Share Posted October 19, 2011 Hi everyone, ive writtern this code and it doesnt work properly, can someone please help me to understand why this doesnt work. Or one better, solve the mystery! Thanks in advance! import java.util.Scanner;/* This program is from lecture 3, it asks the user for their name, then says hello name* if that name = lucy then i want it to say something else.* 19/10/11* @author ahr */public class lecture { public static void main (String[] args) throws Exception { String name; System.out.println("Enter your name"); Scanner Scan = new Scanner(System.in); name = Scan.next(); if (name = "lucy") System.out.print("Hi Rucy Roo"); else System.out.print("hello " + name); }} Link to comment Share on other sites More sharing options...
Synook Posted October 20, 2011 Share Posted October 20, 2011 You should use the Object.equals() method for reference type comparison. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.