Program to Demonstrate Return Type, Ternary Operator , Call by Reference and Odd Even Check in Java (BlueJ)
Code:
OUTPUT:
101 is a ODD number
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;
}
}
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
0 comments:
Confused? Feel free to ask
Post a Comment