Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

test

import java.util.Scanner;

public class QuadraticEquationSolver{
 public static void main(String[] args){
  
   Scanner input = new Scanner(System.in);

//getting variables for equation from user   
   System.out.println("print in a value for a variable");
   int a;
   a = input.nextInt();
   
   System.out.println("print in a variable for b value");
   int b;
   b = input.nextInt();
   
   System.out.println("print in a variable for c value");
   int c;
   c = input.nextInt();
   
   //finding roots
   
   double part1 = Math.sqrt(b*b - 4 * a * c);
   
   double root1 = (-b + part1)/(2 * a);
   double root2 = (-b - part1)/(2 * a);
   
 System.out.println("the roots of the quadratic equation are" + root1 + "and" + root2);
        
    
        
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.