Friday, 18 January 2013


Program to Demonstrate Return Type, Ternary Operator , Call by Reference and Odd Even Check in Java (BlueJ)
Code:
/ ***** PROGRAM TO DEMONSTRATE RETURN TYPE, TERNARY OPERATOR , CALL BY REFERENCE AND ODD EVEN CHECK ******/

public class ReturnDemo
{
     public static int num = 101;
    
    public static void checkOddEven()
    {
         ReturnDemo rd = new ReturnDemo();// object creation
        
      String rply = rd.check(rd);
      System.out.println(rd.num+ " is a "+rply+" number");
    }
    public static String check(ReturnDemo rd)
    {
        // Using ternery operator
        String ans = (rd.num % 2 == 0)? "EVEN" : "ODD";
        return ans;
    }
}

OUTPUT:
101 is a ODD number

Related Posts :



0 comments:

Confused? Feel free to ask

Post a Comment