how can I make a java statement without using an IF statement?

June 29, 2009 - 9:29 pm

I need help writing a program that shows a specific numbers…there are 2 scenarios and I cant use an IF statement.

Any suggestions?

can you use a switch?

or you can simulate an if using the conditions of loops:

eg:

while(condition1 = true)
{

break;
}

while(condition 2 = true)
{

break;
}

2 Responses to “how can I make a java statement without using an IF statement?”

  1. [ J ] a [ Y ] Says:

    can you use a switch?

    or you can simulate an if using the conditions of loops:

    eg:

    while(condition1 = true)
    {

    break;
    }

    while(condition 2 = true)
    {

    break;
    }
    References :

  2. check_himu Says:

    Yeah u can use switch.
    Otherwise use ternary operator.
    <value_variable>=<condition>?:<true_statement>:<false_statement>
    Let's say I want to display which number is bigger. The nos. are a and b.
    int big;
    big=a>b?a:b;
    System.out.println("Bigger No. is "+big);
    References :

Leave a Reply