Skip to main content

Write a Program in java that prints all real solutions to the quadratic equations ax2+bx+c=0. Read a,b,c and use the quadratic formula. If the discriminate b2-4ac is negative, display a message stating there are no real solutions.

Write a Program in java that prints all real solutions to the quadratic equations ax2+bx+c=0.
Read a,b,c and use the quadratic formula.
If the discriminate b2-4ac is negative, display a message stating there are no real solutions.



import java.util.Scanner; 
class quads{ 
 public static void main(String[] args) { 
  Scanner sc = new Scanner(System.in); 
  System.out.println("Eneter the value of a : "); 
  double a = sc.nextDouble(); 
  System.out.println("Enter the value of b : "); 
  double b = sc.nextDouble(); 
  System.out.println("Enter the value of c : "); 
  double c = sc.nextDouble(); 
  double d = b * b - 4 * a * c; 
  if (d > 0.0) { 
   double r1 = (-b + Math.pow(d, 0.5)) / (2.0 * a); 
   double r2 = (-b - Math.pow(d, 0.5)) / (2.0 * a); 
   System.out.println("The roots are " + r1 + " and " + r2); 
  } 
  else if (d == 0.0) { 
   double r1 = -b / (2.0 * a); 
   System.out.println("The root is " + r1); 
  } 
 else { 
  System.out.println("Roots are not real."); 
 } 
 sc.close(); 
 }
}



OUTPUT:

Enter the value of a :
1
Enter the value of b :
5
Enter the value of c :
2
The roots are -0.4384471871911697 and -4.561552812808831





Comments

Popular posts from this blog

Palindrome

প্যালিনড্রোম (অর্থাৎ সামনে থেকে এবং পিছন থেকে সমান.উভয় দিক থেকে পড়লে একই!)  (ক) বাংলায় প্যালিনড্রোম বাক্য :-   সিমার মাসি   বল খেলব   বই চাইব   ঘুরবে রঘু    নাম লেখালেম না    বিকল্প কবি   তুমি কি মিতু ?   মার কথা থাক রমা   কীর্তন মঞ্চ পরে পঞ্চম নর্তকী      কাক কাঁদে কাঁক কা   চেনা সে ছেলে বলেছে সে নাচে    তাল বনে নেব লতা    চার সের চা   ঠাকুরদাদার কুঠা   খা সমস্ত রুটি রুস্তম সখা   না না কেনা না।   না বললে লব না   ওর মা আজ আমারও   বিরহে রাধা নয়ন ধারা হেরবি   থাক রবি কবির কথা   মামাতো মামা   কাকা তো কাকা   রবীন দা দানবীর। (খ) বাংলায় প্যালিনড্রোম নাম :-   নিধুরাম রাধুনি   সুবল লাল বসু   রমা কান্ত কামার   সদানন দাস   রায়মণি ময়রা   হারান রাহা     ইলু দলুই   সুবর্ণা বসু   সদাই দাস (গ) বাংলায় প্যালিনড্রোম শব্দ :- মরম, মলম, দরদ, জলজ, বনমানব, নবজীবন, সহিস, কালিকা, সরেস, তফাত, বাহবা, সন্ন্যাস,...