Im learning java, and having trouble with some simple code.
Heres my code, can you tell me why the output is disregarding the "Correct!" statement at the end

package Otm;
import java.util.*;
public class Otm {


public static void main(String arg[]) {
Scanner sc=new Scanner(System.in);
String Wash="Washington";
String Ham="Hamilton";
String Jac="Jackson";
int choice;
int dollar;
String person;

System.out.println("Type 1 to enter a denomination, 2 to enter a last name: ");
choice=sc.nextInt();

if(choice==1){
System.out.println("Choose a denomination: ");
Scanner b=new Scanner(System.in);
dollar=b.nextInt();

if(dollar==1){
System.out.println("Which person appears on the 1 dollar bill?");
Scanner l=new Scanner(System.in);
person=l.next();

if(person==Wash){
System.out.println("Correct!"); 
}

}



}
}
}

also i dont know why the code tags arent working, im putting them in the brackets.

import java.util.*;

public class Otm {

    public static void main(String arg[]) {

    Scanner sc=new Scanner(System.in);

    String Wash="Washington";

    String Ham="Hamilton";

    String Jac="Jackson";

    int choice;

    int dollar;

    String person;

    System.out.println("Type 1 to enter a denomination, 2 to enter a last name: ");

    choice=sc.nextInt();

    if(choice==1){

    System.out.println("Choose a denomination: ");

    Scanner b=new Scanner(System.in);

    dollar=b.nextInt();

    if(dollar==1){

    System.out.println("Which person appears on the 1 dollar bill?");

    Scanner l=new Scanner(System.in);

    person=l.next();

    if(person.compareTo("wash") == 0){

    System.out.println("Correct!");

                }//end of inner most if

            }//end of outer if

        }//end of outer most if

    }//end of main method

}//end of class

the first thing you have an extra array bracket which you have to remove , the second thing person is a String and you can't compare 2 Strings with '==' you had to use .compareto() method ...hope that helped you

that did help tnx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.