请检查这些代码

时间:2015-06-23 20:41:19

标签: if-statement equals

你可以查看这些代码吗? 我找不到问题。 "如果"没有动作! 它应该检查用户名和密码和年龄。 之后,如果所有细节都是真的,将回答为真,除非回答错误。但是"如果"别回答。

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 个答案:

答案 0 :(得分:0)

你在代码中犯了很多错误。

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