J
J
Java Developer2021-03-14 22:17:24
Java
Java Developer, 2021-03-14 22:17:24

How to make sure that when you enter the word "Man" in the console, the code in this if is executed?

System.out.println("Введите ваш пол");
        
         if (?? ) {
            double d = (x - y) * z;
            System.out.println("Вес=" + d);
        }


How can I make the code specified in if () be executed when the word "Man" is entered in the console?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BorLaze, 2021-03-14
@BorLaze

ummm... read the documentation on "string comparison"?

O
Orkhan, 2021-03-14
Hasanly @azerphoenix

Greetings!
Here is a simple example:

public class Main {
  
  public static void main(String ... args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Введите ваш пол:");
    String gender = sc.nextLine();
    if(gender.equals("Мужчина")) {
      double d = (x - y) * z;
      System.out.println("Вес=" + d);
    }
  }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question