• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

if and else

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everybody,
if (a >4)
System.out.println("test1");
else if (a >9)
System.out.println("test2");
else
System.out.println("test3");


What will print 'test 2'?

A. less than 0
B. less than 4
C. between 4 and 9
D. greater than 9
E. none

given answer is e.but i think answer is d.
please explain me.
thanks
sri.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sri,
What will print 'test 2'?
if (a >4)
System.out.println("test1");
else if (a >9)
System.out.println("test2");
else
System.out.println("test3");
A. less than 0
B. less than 4
C. between 4 and 9
D. greater than 9
E. none
Sri, "test 2 " will never be printed bcoz of the earlier "if ".
If a is greater than 4, the first "if" satisfies the condition
so "test 1" is printed. Note 9 is obviously greater than 4 ...right ? which satisfies the first condition.
Hope u got it.

ALL THE BEST FOR UR EXAM.
Aruna
 
Your mother is a hamster and your father smells of tiny ads!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic