0

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



    }

}

Edited by mike_2000_17: Fixed formatting

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by javanub123
0

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

0

ahh kk. thanks for the info on the scanner

im still puzzled on how to define password1

remember, i just started learnin yesterday.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.