Which two code fragments can be independently placed at…

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?

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



Leave a Reply 1

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


renko

renko

Answer: A,C
Use CLI with argument 90 and then 80

package q081;

public class Test {

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

//C: True
//discount = (qty >= 90) ? 0.5 : (qty > 80) ? 0.2 : 0;

/*D: False
if (qty > 80 && qty = 90) {discount = 0.5;}
else {discount = 0;} */

/*E: False
discount = (qty > 80) ? 0.2 : (qty >= 90) ? 0.5 : 0;*/

//Output
System.out.println(discount);
}
}