A couple of Java questions?

Q19. Which of the following conditions does not test whether x is between 1 and 10 (inclusive)? A) 1 <= x && x <= 10 B) !(x < 1 || 10 < x) C) !(x <= 1 || x >= 10) D) 10 >= x && x >= 1 Q20. Which of the following statements is correct? A) It is a good idea to write the first... show more Q19. Which of the following conditions does not test whether x is between 1 and 10 (inclusive)?
A) 1 <= x && x <= 10
B) !(x < 1 || 10 < x)
C) !(x <= 1 || x >= 10)
D) 10 >= x && x >= 1




Q20. Which of the following statements is correct?
A) It is a good idea to write the first test cases before the program is written completely.
B) It is not a good idea to write the first test cases before the program is written completely.
C) It is not a good idea to write the first test cases after the program is written completely.
D) It is a good idea to write the first test cases after the program is written completely.

Q23. The statement y = x >= ? x : -x; is similar to ____.
A) if,(x >= 0) y = x;
B) if,(x >= 0) y = x; else y = -x;
C) if,(x >= 0) y = -x;
D) if,(x >= 0) y = -x; else y = x;

Q35. Which of the following code fragments is considered bad style?

a)
public int getYears()
{
return years;
}

b)
for(int i = 1; i <= years; i++)
{
if(balance >= targetBalance)
i = years + 1;
else
{
double interest = balance * rate / 100;
balance = balance + interest;
}
}

c)
public double getBalance()
{
return balance;
}

d)
for (int i = 1; i <= n; i++)
{
double interest = balance * rate / 100;
balance = balance + interest;
}
2 answers 2