Top Posts
Reliance Jio launches streaming platform JioGamesWatch
Microsoft Teams down for thousands of users
Carbon: Google programming language as a C++ successor
JavaScript MCQs II
JavaScript MCQs I
Problem Solving Approach
Terms related to Network Security
Set in C++STL
Computer network attack (CNA)
Indexing in DBMS
TECHARGE
  • HOME
  • BLOGS
  • TUTORIALS
    • ALL TUTORIALS
    • PROGRAMMING TUTORIALS
      • JAVA TUTORIALS
      • C++ TUTORIAL
      • C PROGRAMMING TUTORIALS
      • PYTHON TUTORIAL
      • KNOWLEDGE MANAGEMENT TUTORIALS
      • DATA STRUCTURE AND ALGORITHM TUTORIALS
      • PROGRAMMING EXAMPLES
        • CPP EXAMPLES
        • JAVA EXAMPLES
        • C++ GRAPHICS PROGRAM
    • PROJECTS
      • PYTHON PROJECTS
      • SWIFT PROJECT
    • PPROGRAMMING QUIZ
    • DBMS TUTORIALS
    • COMPUTER NETWORK TUTORIALS
    • COMPUTER NETWORK SECURITY TUTORIALS
    • E COMMERCE TUTORIALS 
    • AWS TUTORIAL
    • INTERNET OF THINGS
    • CHEATSHEET
  • MORE
    • JOBS AND INTERNSHIPS
    • INTERVIEW PREPARATION
    • TECH BOOK
    • TECH NEWS
    • INSTAGRAM GALLERY
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • WEB STORIES
    • CONTACT US
  • WRITE +
  • ABOUT US
  • HIRE US
  • BEST COURSES
Java Program Examples

Java Program to Find all Roots of a Quadratic Equation

by anupmaurya December 18, 2021
written by anupmaurya 0 comment

In this program we are going to find all roots of a Quadratic Equation

public class Quadratic { public static void main(String[] args) { double a = 2.3, b = 4, c = 5.6; double root1, root2; double determinant = b * b - 4 * a * c; // condition for real and different roots if(determinant > 0) { root1 = (-b + Math.sqrt(determinant)) / (2 * a); root2 = (-b - Math.sqrt(determinant)) / (2 * a); System.out.format("root1 = %.2f and root2 = %.2f", root1 , root2); } // Condition for real and equal roots else if(determinant == 0) { root1 = root2 = -b / (2 * a); System.out.format("root1 = root2 = %.2f;", root1); } // If roots are not real else { double realPart = -b / (2 *a); double imaginaryPart = Math.sqrt(-determinant) / (2 * a); System.out.format("root1 = %.2f+%.2fi and root2 = %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart); } } }
Code language: JavaScript (javascript)

What You get as Output , After running the program

root1 = -0.87+1.30i and root2 = -0.87-1.30i
java examplesjava programJava Program to Find all Roots of a Quadratic Equation
Share 1 FacebookTwitterLinkedinRedditWhatsappTelegramEmail
anupmaurya

Hey there, My name is Anup Maurya. I was born with love with programming and works at TCS. One of best global (IT) services and consulting company as System Administrator . I also love graphics designing. It's my pleasure to have you here.

previous post
Java Program to Swap Two Numbers
next post
Java Program to Find the Largest Among Three Numbers

You may also like

Arguments in Java with Examples

Bitwise operators in Java

Java Program to Check Whether a Number is Even or Odd

Java Program to Check Whether an Alphabet is Vowel or Consonant

Program in Java to show concept of multilevel inheritance

Java Program to Find the Largest Among Three Numbers

Java Program to Swap Two Numbers

Java Program to Compute Quotient and Remainder

Java Program to Find ASCII Value of a character

Java Program to Add Two Integers

JAVA EXAMPLE

  • Java Program to print a number
  • Java Program to Add Two Integers
  • Java Program to Find ASCII Value of a character
  • Java Program to Check Whether a Number is Even or Odd
  • Java Program to Check Whether an Alphabet is Vowel or Consonant
  • Java Program to Find the Largest Among Three Numbers
  • Java Program to Find all Roots of a Quadratic Equation
  • Java Program to Swap Two Numbers
  • Java Program to Compute Quotient and Remainder

Words from Readers

I Just go mad with this website I love the content and the way it you present I can easily understand anything from this Thank you everyone who are made this possible!

–Paras Singh Kaphalia

Recent Posts

  • Reliance Jio launches streaming platform JioGamesWatch

    August 6, 2022
  • Microsoft Teams down for thousands of users

    July 21, 2022
  • Carbon: Google programming language as a C++ successor

    July 19, 2022
  • JavaScript MCQs II

    July 11, 2022
  • JavaScript MCQs I

    July 10, 2022

EDUCATIONAL

  • 5+ Best Humanoid Robots In The World

  • Difference between Google Cloud Platform, AWS and Azure

  • Google Apps You Should Be Using in 2022

  • Top Sites From Where You Can Learn

  • PyScript: Python in the Browser

  • Best Fake Email Generators (Free Temporary Email Address)

  • How to Find Out Who Owns a Domain Name

  • Mobile phone brands by country of origin

  • How to start a new YouTube Channel in 2022

  • Best way to use google search you won’t believe exist

CHEATSHEET

  • HTML Cheatsheet

  • C++ Programming language Cheatsheet

  • Git and Github 2022 Cheat Sheet

  • ReactJs Cheatsheet

  • Linux Commands Cheat Sheet

  • C Programming language Cheatsheet

  • Scala Cheatsheet

PROJECTS

  • Python text to Speech

  • StopWatch using Python

  • Python Rock Paper Scissors Game

  • Currency Converter in Python

  • Alarm clock GUI application with tkinter

  • Print emojis using python without any module

  • Country Date and Time using Python

  • Covid-19 Tracker Application Using Python

  • Python | GUI Calendar using Tkinter

  • Python: Shutdown Computer with Voice

  • Python GUI Calculator using Tkinter

  • Convert an Image to ASCII art using Python

TUTORIALS

  • JAVA TUTORIAL
  • COMPUTER NETWORK
  • DBMS TUTORIAL
  • E-COMMERCE TUTORIAL
  • KNOWLEDGE MANAGEMENT
  • C++ PROGRAMMING
  • COMPUTER NETWORK SECURITY
  • AMAZON WEB SERVICES

TECH NEWS

  • Reliance Jio launches streaming platform JioGamesWatch

  • Microsoft Teams down for thousands of users

  • Carbon: Google programming language as a C++ successor

  • 5+ Best Humanoid Robots In The World

TERMS & POLICY

  • PRIVACY POLICY
  • TERMS AND CONDITIONS

COMPILERS

  • JAVA COMPILER
  • PYTHON COMPILER
  • JS COMPILER
  • C++ COMPILER
  • C COMPILER

JOBS AND INTERNSHIPS

  • TCS off-campus hiring 2022 for software engineers- 2019, 2020, & 2021 Batches

    February 27, 2022
  • Deloitte Recruitment For Any Graduates as Learning Operations Associate Analyst

    February 18, 2022
  • HP Recruitment For Tech Support Intern Position

    February 16, 2022
  • EY Hiring- PAS Global Immigration Advanced Analyst

    February 14, 2022
  • Amazon Recruitment Drive for Virtual Customer Support Associate Position

    February 12, 2022
Join Us On Telegram

@2019-21 - All Right Reserved. Designed and Developed by Techarge

TECHARGE
  • HOME
  • BLOGS
  • TUTORIALS
    • ALL TUTORIALS
    • PROGRAMMING TUTORIALS
      • JAVA TUTORIALS
      • C++ TUTORIAL
      • C PROGRAMMING TUTORIALS
      • PYTHON TUTORIAL
      • KNOWLEDGE MANAGEMENT TUTORIALS
      • DATA STRUCTURE AND ALGORITHM TUTORIALS
      • PROGRAMMING EXAMPLES
        • CPP EXAMPLES
        • JAVA EXAMPLES
        • C++ GRAPHICS PROGRAM
    • PROJECTS
      • PYTHON PROJECTS
      • SWIFT PROJECT
    • PPROGRAMMING QUIZ
    • DBMS TUTORIALS
    • COMPUTER NETWORK TUTORIALS
    • COMPUTER NETWORK SECURITY TUTORIALS
    • E COMMERCE TUTORIALS 
    • AWS TUTORIAL
    • INTERNET OF THINGS
    • CHEATSHEET
  • MORE
    • JOBS AND INTERNSHIPS
    • INTERVIEW PREPARATION
    • TECH BOOK
    • TECH NEWS
    • INSTAGRAM GALLERY
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • WEB STORIES
    • CONTACT US
  • WRITE +
  • ABOUT US
  • HIRE US
  • BEST COURSES