nooby nooby - 1 year ago 91
Java Question

Java how to check which condition is true

Is there anyway to make the program say which condition is correct?

public static void main(String[] args) throws IOException, InterruptedException {
Boolean a = true;
Boolean b = false;
Boolean c = null;
if (a == true || b == false || c == true) {

is the only one that is correct, would there be away too make it print "a is the only condition that is correct"

Answer Source
if (a) {
    System.out.println("a is the condition that is correct");
//Edit by comment. Thanks
if (!b) {
    System.out.println("b is the condition that is correct");

if (c) {
    System.out.println("c is the condition that is correct");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download