i started learning java yesterday and its my first programming language to learn. ive covered most of the basics and such but im stuck at one thing

i have a program written that asks for a password
i want it to compare the user input to the actual password using an if statement.

heres what i have so far

import java.util.Scanner;


public class UserInput {


    public static void main(String[] args) {

        System.out.println("Please Enter Your Name");
        Scanner name = new Scanner (System.in);
        String inName = name.nextLine();
        System.out.println("Welcome " + inName);
        System.out.println("Please enter your password");
        Scanner password = new Scanner (System.in);
        String inPassword = password.nextLine();

        if (inPassword.equals(password1)) {
            // i get an error here
            //ive tried making a string for the actual password but nothing seems to work

            System.out.println("access granted");
        } else {

            System.out.println("access denied");
        }



    }

}

You haven't defined the variable: password1
Also you don't need 2 Scanner objects.
Use one and call the method nextLine as many times as you like

ahh kk. thanks for the info on the scanner

im still puzzled on how to define password1

remember, i just started learnin yesterday.

never mind i figured it out! thanks for your help =)

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.