125k views
3 votes
Consider the following code snippet: int score = 0; double price = 100; if (score > 0 && price < 200 && price / score > 10) { System.out.println("buy"); } Which of the following statements is true on the basis of this code snippet? The output is buy. The code snippet compiles and runs, but there is no output. The code snippet doesn't compile. The code snippet causes a divide-by-zero error.

User Covati
by
4.5k points

1 Answer

5 votes

Answer:

The code snippet compiles and runs, but there is no output.

Step-by-step explanation:

The condition is

  • score > 0 && price < 200 && price / score > 10

score = 0

price = 100

[(0) > 0] and [(100) < 200] and [100)/(0) > 10]

false and ........

Since the first condition is false, the program will not validate the other conditions because the conditional "and" is false when at least one of the conditions is false

User SimplyPhy
by
4.7k points