• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Operators - Dan Chisholm question

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am stumped by a single topic question in Dan's excellent mock exams. I literally cannot understand the boolean = statements. Could someone help?

Here is the Q and A:

Question 14
class EBH023 {
static String m1(boolean b){return b?"T":"F";}
public static void main(String [] args) {
boolean b1 = false?false:true?false:true?false:true;
boolean b2 = false?false true?false true?false:true));
boolean b3 = ((false?false:true)?false:true)?false:true;
System.out.println(m1(b1) + m1(b2) + m1(b3));
}}

What is the result of attempting to compile and run the program?

a. Prints: FFF
b. Prints: FFT
c. Prints: FTF
d. Prints: FTT
e. Prints: TFF
f. Prints: TFT
g. Prints: TTF
h. Prints: TTT
i. Run-time error
j. Compile-time error
k. None of the above


Answer:

14 b Prints: FFT The expression used to assign variable b1 is equivalent to the expression used to assign variable b2. The results demonstrate that the conditional operator (? groups from right-to-left.

Help!

Thanks in advance.

Jerry Bustamente
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Code is like this.
=====================================================



Thanks,
Mubeen Shaik.

[ December 14, 2004: Message edited by: Mubeen Shaik ]

[ December 14, 2004: Message edited by: Mubeen Shaik ]
[ December 14, 2004: Message edited by: Mubeen Shaik ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see this thread which analyzes this question:
https://coderanch.com/t/247148/java-programmer-SCJP/certification/Couple-questions-Operators
 
Slime does not pay. Always keep your tiny ad dry.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic