Given the code fragment:

Given the code fragment:

And given the requirements:
If the value of the qty variable is greater than or equal to 90, discount = 0.5 If the value of the qty variable is between 80 and 90, discount = 0.2 Which two code fragments can be independently placed at line n1 to meet the requirements?

A. Option A
B. Option B
C. Option C
D. Option D
E. Option E

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “Given the code fragment:

  1. A C

    public static void main(String[] args) {
    double discount = 0;
    int qty = Integer.parseInt(args[0]);
    // if(qty>=90){discount=0.5;}
    // if(qty >80 && qty=90 ? 0.5 : (qty>80)? 0.2 : 0 );

  2. Answer A, C:

    B and D are not correct because there is two conditional statements and in each one there is an else statement that is assigning the value of discount to 0. While D is not correct because the (qty >= 90) is unreachable and would always equal to false.

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.