Search:

Type: Posts; User: Json

Search: Search took 0.09 seconds.

  1. Replies
    7
    Views
    2,050

    Re: Problem with condition

    This code works fine for me.



    int num1 = -1;
    String x = (num1 >= 0 ? "positive" : "negative");
    System.out.println(x);


    // Json
  2. Replies
    7
    Views
    2,050

    Re: Problem with condition

    Rewrite it to be this.


    String x=(num1 >= 0 ? "positive" : "negative");

    I think your parenthesis was in the wrong place.

    // Json
  3. Replies
    7
    Views
    2,050

    Re: Problem with condition

    In the code you have.


    int x=(num1>=0)? "positive":"negative";

    You are trying to check the value of num1 and return a string and assign it to int x. Change the int x to be String x.

    // Json
Results 1 to 3 of 3