Question: The program allowed the user to enter the values of a,b, and c into the array. Once the user has entered the input, the program

The program allowed the user to enter the values of a,b, and c into the array.

Once the user has entered the input, the program displays the solutions to the quadratic equation.

Attached is a program written by one of your classmates.

There is one compilation errors and one run-time error in the program.

After you fix the errors. Try running the program with input

a=1, b= -3 , and c= 2

The expected output is Sol1= 2 and Sol2= 1

But the actual output is Sol1= -1 and Sol2= -2

This is a case of Logic error

Which statement needs to be modified?

The error is in a line that is between lines 12 and 15.

the program is:

import java.util.Scanner; public class MyCalculator { public static void main(String args[]) { Scanner input = new Scanner (System.in); int array[3] ; System.out.println("Enter a:"); array[0]= input.nextInt(); System.out.println("Enter b:"); array[1]= input.nextInt(); System.out.println("Enter c:"); array[3]= input.nextInt(); int b = array[1]; double squreRoot = Math.sqrt( Math.pow(array[1], 2 - (4*array[0]*array[2]) ) ; double sol1= ( b + squreRoot) / (2*array[0]) ; double sol2= ( b - squreRoot) / (2*array[0]) ; System.out.printf("Sol1: %d ",(int)sol1); System.out.printf("Sol2: %d ",(int)sol2); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!