(2) Declare a double variable called quadratic . Initialize the variable to one
ID: 646840 • Letter: #
Question
(2) Declare a double variable called quadratic. Initialize the variable to one of the roots of the quadratic formula (assuming there are variables called a, b, and c):
(-b + square-root(b^2 - 4ac))/2a
---------------------------------------------------------
(3) Convert the following Boolean expression to an equivalent expression that doesn't contain any !'s:
!(grade > 50 || percentAttended >= 0.9)
---------------------------------------------------------
(4) Here's code that uses a while-loop. Write a piece of equivalent code (i.e. code that behaves exactly the same for all possible input values) that uses a do-while loop instead.
Scanner keybd = new Scanner (System.in);
int inputValue = keybd.nextInt();
while (inputValue < 10){
inputValue++;
System.out.println(inputValue);
}
Explanation / Answer
(2) Declare a double variable called quadratic. Initialize the variable to one of the roots of the quadratic formula (assuming there are variables called a, b, and c):
(-b + square-root(b^2 - 4ac))/2a
double quadratic = (-b + Math.sqrt(b*b - 4*a*c))/(2*a);
(3) Convert the following Boolean expression to an equivalent expression that doesn't contain any !'s:
!(grade > 50 || percentAttended >= 0.9)
!(grade > 50) && !(percentAttended >= 0.9)
grade <=50 && percentAttended<0.9
(4) Here's code that uses a while-loop. Write a piece of equivalent code (i.e. code that behaves exactly the same for all possible input values) that uses a do-while loop instead.
Scanner keybd = new Scanner (System.in);
int inputValue = keybd.nextInt();
while (inputValue < 10){
inputValue++;
System.out.println(inputValue);
}
do{
if(inputValue<10){
inputValue++;
System.out.println(inputValue);
}
}while (inputValue < 10);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.