Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions