Writing a complex Java boolean expression -


i trying write code if following conditions met marry me otherwise lost.

conditions need met:

22 27 year old male, non-smoking, under 72 inches tall, under 160 pounds, good-looking, able relocate.”

this code have far written. however, prints lost though believe matches given criteria? wrong?

furthermore, how can put in terms of single boolean?

public class marry {      public static void main(string[] args) {         int weight = 150;         int age = 24;         int height = 71;         boolean isasmoker = false;         boolean ismale = true;         boolean isgoodlooking = true;         boolean isabletorelocate = true;          if (((weight < 160 && (age <= 27 && age >= 22)) && ((height < 72) && ((isasmoker = false) && (ismale = true))) && ((isgoodlooking = true) && (isabletorelocate = true)))) {             system.out.println("marry me!");         }         else {             system.out.println("get lost!");         }     } } 

thanks

try little piece of code deciding problem:

class person {     private int weight;     private int age;     private int height;     private boolean isasmoker;     private boolean ismale;     private boolean isgoodlooking;     private boolean isabletorelocate;      public person(int weight, int age, int height, boolean isasmoker, boolean ismale, boolean isgoodlooking, boolean isabletorelocate) {         this.weight = weight;         this.age = age;         this.height = height;         this.isasmoker = isasmoker;         this.ismale = ismale;         this.isgoodlooking = isgoodlooking;         this.isabletorelocate = isabletorelocate;     }      public boolean isgood() {         return weight < 160 && age <= 27 && age >= 22 &&                 height < 72 && !isasmoker && ismale &&                 isgoodlooking && isabletorelocate;                // (variable == true) => variable                // (variable == false) => !variable     }      public static void main(string[] args) {         person person = new person(150, 24, 71, false, true, true, true);         system.out.println(person.isgood() ? "marry me!" : "get lost!");     } } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -