Please check these code

55 Views Asked by At

could you check these codes? I can't find the problem. "If" has no action! It should check username and password and age. After that if all of details are true will answer true unless will answer false.But "If" don't answer.

import java.util.Scanner;

 public class Class2 {

    public static void main(String[] args) {

        int age;
        String password = "big.110@go";
        String username = "big";

        Scanner keyboardInput = new Scanner(System.in);
        System.out.print("Please enter your Usename: ");
        username = keyboardInput.next();
        System.out.print("Please enter your age: ");
        age = keyboardInput.nextInt();
        System.out.print("Please enter your password: ");
        password = keyboardInput.next();
    if(keyboardInput.next().equals(username)
            && keyboardInput.nextInt() >= 18
            && keyboardInput.equals(password)) {
                System.out.print("Welcome");
            } else {
                System.out.print("Something is wrong!\n Try again");
            }
    }
}
1

There are 1 best solutions below

1
On

You made a lot of mistake in your code.

import java.util.Scanner;


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

      int age;
      String password1 = "big.110@go";
      String username1 = "big";

      Scanner keyboardInput = new Scanner(System.in);
      System.out.print("Please enter your Usename: ");
      String username = keyboardInput.nextLine();
      System.out.print("Please enter your password: ");
      String password = keyboardInput.nextLine();
      System.out.print("Please enter your age: ");
      age = keyboardInput.nextInt();

      if(username.equals(username1)
              && password.equals(password1)
              && age>=18 ) {
          System.out.print("Welcome");
      } else {
          System.out.print("Something is wrong!\n Try again");
      }
    }
}