Jump to content
slashjack

Why Wont This Run!? Please Help

Recommended Posts

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); }}

  • Like 1

Share this post


Link to post
Share on other sites

You should use the Object.equals() method for reference type comparison.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...