1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
JulsSmile [24]
3 years ago
10

Use java to write a program that finds the real rooots of the quadratic equation ax^2+bx+c using the quadratic formula.

Computers and Technology
1 answer:
Artyom0805 [142]3 years ago
8 0

Answer:

The program to this question can be given as:

Program:

//import package.

import java.util.*;

public class quadratic           //define class.

{

public static void main(String[] args) //define main method

{

double a,b,c;          //decalre varibale.

Scanner in=new Scanner(System.in);       //creating scanner class object.

System.out.print("Enter coefficient a: ");          //print message.

a=in.nextDouble();                      //user input.

System.out.print("Enter coefficient b: ");

b=in.nextDouble();

System.out.print("Enter coefficient c: ");

c=in.nextDouble();

solve(a,b,c);                //calling function.

}

public static void solve(double a,double b,double c)      //define method.

{

double dis;  //define variable.

dis=b*b-4*a*c;

System.out.println("The roots of "+a+"x^2 + "+b+"x + "+"("+c +")" +" are:");

//conditional statement.

if(a==0)    //by definition-denominator will be 0

{

System.out.println("Error: no real roots exist");

}

else if(dis<0)         //by definition, negative discriminant means roots are imagenary

{

System.out.println("Error: no real roots exist\n");

}

else                          //get the 2 roots

{

dis=Math.sqrt(dis);

System.out.println("first root= "+(-b+dis)/(2*a)+"\nSecond root= "+(-b-dis)/(2*a));

}

}

}

Output:

Enter coefficient a: 6

Enter coefficient b: 11

Enter coefficient c: -35

The roots of  6.0x^2 + 11.0"x +(-35)  are:

first root= 1.666666666667

Second root=-3.5

Explanation:

In the above program firstly we import packages for the user input. Then we define class. In this class we define a main method and function i.e solve function. In the main method we create the scanner class object and input the value from the user and pass the value to the function and call the function. In the solve function, we use the conditional statement that checks any of the input values is not equal to 0. if any value is equal to 0 it prints error message otherwise it prints the quadratic value and its roots.

You might be interested in
On a wireless router, what gives out IP addresses?<br> DHCP<br> DNS<br> WPA<br> WPS
attashe74 [19]

Answer:

DHCP

Explanation:

The only option can give IP addresses is the DHCP The Dynamic Host Configuration Protocol, because the DNS (Domain Name System) only translates IP addresses to a hostname, and WPS (Wi-Fi Protected Setup) or WPA (Wi-Fi Protected Access) if for security network, doesn't matter if is a wireless router, in a network always DHCP gives the IP addresses.

7 0
3 years ago
Write the name of test for the given scenario. Justify your answer.
Snowcat [4.5K]

Answer:

Cevap b okey xx

Explanation:

Sinyorrr

8 0
3 years ago
What is the best thing about Tuesday’s in general? Why?
Stolb23 [73]

Answer:

tbh I really don't know what you mean

4 0
4 years ago
Assuming that a valid price should be between 30 and 50, what does the following code snippet do? final int MIN_PRICE = 30; fina
Lorico [155]

Answer:

This code snippet ensures that the price value is between 30 and 50.

Explanation:

If the price is not between 30 and 50 then the output will be "Error:  ...."

4 0
4 years ago
Which item would not generate a desktop alert by default in Outlook 2016?
Dafna11 [192]

New contact created does not generate a desktop alert by default.

5 0
3 years ago
Other questions:
  • Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE p
    8·1 answer
  • What is an activity that can help you enhance the appearance of your computer’s desktop?
    12·2 answers
  • What is an example of a source that is less likely to be copyrighted?
    7·2 answers
  • Define a class named ComparableSquare that extends Square (defined above) and implements Comparable. Implement the compareTo met
    7·1 answer
  • Apex
    5·2 answers
  • What correctly describes the features of the service called kickstarter?
    14·2 answers
  • Give several reasons why Python is such a great programming language. Explain how Python is related to flowcharts.
    9·1 answer
  • 1.5 question 3 on edhesieve
    6·1 answer
  • Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
    7·1 answer
  • Why does this happen
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!