jeudi 21 novembre 2019

Using if, else statements in scan (Java)

import java.util.Scanner;

public class SecondProject
{
    public static void main(String[] args)
    {

        Scanner input = new Scanner(System.in);
        String name = "Eldar";

        System.out.println("Hello enter the password: ");
        String password = input.nextLine();

        System.out.printf("Password: %s \n", password);

        if (password != name) {
            System.out.println("Wrong password!");
        } else {
            System.out.printf("Welcome %s", name);
        }
    }
}

Here's the code above. Pretty simple programm, but I can't fix it, heh. The problem is that the if, else blocks don't work correctly. Also thanks for help :)

Aucun commentaire:

Enregistrer un commentaire