exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 38 discussion

Actual exam question from Oracle's 1z0-808
Question #: 38
Topic #: 1
[All 1z0-808 Questions]

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? (Choose two.)

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
  • E. Option E
Show Suggested Answer Hide Answer
Suggested Answer: AC 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
vic88
8 months ago
Selected Answer: AC
D is not right because it's double checked again after if (qty >=90) {discount = 0.5), reset the discount to 0.
upvoted 1 times
...
BelloMio
1 year, 1 month ago
Ok I got why D is wrong. it is wrong in the case if qty is 85 for example. it will go in the first if condition which will make discount = 0.2 all good. Then it will also go in the second if condition where it will go into the else statement and assign discount = 0, making the code not correct
upvoted 2 times
...
DarGrin
1 year, 9 months ago
Selected Answer: AC
Only A and C are correct
upvoted 1 times
...
anassasl
1 year, 10 months ago
why D is not correct ?
upvoted 1 times
montoyamontes
1 year, 9 months ago
If qty = 80 then the result must be discount=0.2 if(qty> 80 && qty <90 ) { //80>90: true && 80<90: true discount = 0.2 // this is correct }else{ discount =0 //this is ignored } if(qty>=90){ //80>=90:false discount = 0.5 //this is ignored so go to else }else{ // discount=0 } Finally discount=0 != 0.2
upvoted 1 times
...
...
Vicky_65
2 years, 3 months ago
Selected Answer: AC
thisis correct
upvoted 1 times
...
carloswork
2 years, 9 months ago
Selected Answer: AC
Answer is AC. It boring to test... It is necessary to change the value of the variable 'qty' to perform the test. The code can be compiled on the command line and the value passed by "args" or simply change the value of this variable directly in the code. That's it. To test: public static void main(String[] args) { double discount = 0; int qty = Integer.parseInt(args[0]); qty=90; // change here // Answer A if (qty >= 90) { discount = 0.5; } System.out.println(discount); if (qty > 80 && qty < 90) { discount = 0.2; } System.out.println(discount); // Answer C discount = (qty >= 90) ? 0.5 : (qty > 80)? 0.2: 0; System.out.println(discount); }
upvoted 1 times
...
kkaayyyy
2 years, 9 months ago
A and C are the correct options because in Option B we are using the discount variable twice, and thus only the second discount's value will be the final updated value in Option D only the case where qty >= 90 will work in Option E everytime the output printed will be 0.2 no matter if the condition is 1st or 2nd.
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...