Share on Google+Share on Google+

SCJP Module-2 Question-8

Advertisement
This program refreshes your concepts of Core Java and also helps in preparation of SCJP Examination

What is the Output of the following code :

public class Example8 {
public static void main(String[] args) {
System.out.println(check(null, 3));
System.out.println(check("hello", 7));
System.out.println(check("bye", 2));
System.out.println(check("hai", 3));
}

public static int check(String a, int n) {
if (n == 7)
return n;
else if (n == 3) {
if (a != null)
return 5;
} else if (n == 5 && a != null) {
if (a.equals("hai"))
return 3;
else if (a.equals("bye"))
return 4;
}
return -3;
}
}

What is the output of the following code :

1. -3

2. 7

3. -3 7 -3 5

4.  5

Answer :

(3)

Advertisements

Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.