Saturday, 28 September 2013

How to end with one result with an if statement on java?

How to end with one result with an if statement on java?

if (number1 + 8 == number2 || number1 - 8 == number2){
if (name1.equals(name2)){
if (cod1 == cod2){
if (some1.equals(some2)){
System.out.println("They're in the same group");
}
System.out.println("They are in the same column");;
}
System.out.println("They are in the same section");
}
System.out.println("They are in the same subgroup");
}
else{
System.out.println("They are different");
}
}
}
How could I change this so that I only get one message at the end? Right
now it gives all the messages or just the They are different. I know I
can't put an actual break since this isn't a loop, but what action could I
take in this problem? Would I have to rewrite it? Thank You for the help.

No comments:

Post a Comment