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

Indexing in DBMS

Indexing in DBMS Indexing is used to optimize the performance of a database by minimizing the number of disk accesses required when a query is processed.  The index is a type of data structure. It is used to locate and access the data in a database table quickly. Index structure: Indexes can be created using some database columns. The first column of the database is the search key that contains a copy of the primary key or candidate key of the table. The values of the primary key are stored in sorted order so that the corresponding data can be accessed easily.  The second column of the database is the data reference. It contains a set of pointers holding the address of the disk block where the value of the particular key can be found. Indexing Methods Ordered indices The indices are usually sorted to make searching faster. The indices which are sorted are known as ordered indices. Example: Suppose we have an employee table with thousands of record and each of which is 10 byte...

Book Photography Tips

বইছবি সুন্দর করার জন্য কয়েকটি পরামর্শঃ ১। প্রথম তো দিনের আলোতে বইয়ের ছবি তুলুন। গুমোট অন্ধকারে তোলা ছবির লুক ভালো আসে না। রাতে লাইটের আলোতে তোলা ছবির লুকও যথেষ্ট ভালো আসে না। ২। যে বইটার ছবি তুলবেন, শুধুমাত্র ঐ বইটার দিকে ক্যামেরার ফোকাস রাখুন। ডেকোরেশনের জন্য অন্য বই সাথে রাখতে পারেন, কিন্তু ঐসকল বইয়ের নাম যেন দেখা না যায়। ঐসকল বইয়ের পেছনের মলাট খোলা রেখে ছবি তুলুন। একটা বই উল্টো করে অন্য বইটা ঢেকে দিন। ৩। বইয়ের বেকগ্রাউন্ডে পুরোপুরি সাদা বা এক কালারের রঙিন কাপড় বিছিয়ে ছবি তুলুন। ছবির সৌন্দর্য অনেকগুণ বাড়বে। ৪। পারতপক্ষে বইয়ের সাথে দু-একটি বুকমার্ক রাখুন। ছবি মানানসই দেখাবে। ৫। সৌন্দর্য বৃদ্ধির জন্য প্রয়োজনীয় উপকরণ যেমন:  চায়ের কাপ, মগ, কালার পেপার, ফুল, রঙিন পাতা, ইত্যাদি আনুষঙ্গিক জিনিসপত্র সাথে রেখে ডেকোরেশন করে এরপর বইয়ের ছবি তুলুন। আগের চেয়ে বেটার আসবে ছবি। ৬। ছবি তোলার আগে উপকরণগুলো বিভিন্ন পজিশনে সাজিয়ে নিন। কোনো উপকরণ দুটোর বেশি রাখবেন না। হিজিবিজি দেখাবে। আবার অনেকগুলো উপকরণ সাথে রেখে ছবি তুলতে যাবেন না। বেমানান লাগবে। ৭। বইয়ের বিষয়বস্তুর সাথে খাপ খায় এমন শব্দ, বাক্য সাদা...

List vs Tuple

List vs Tuple (Image by - Sharma Guides | Subham232330) List | |- Syntax :- [2,3,4] | |- Mutable :- Elements can be changed after creation. | |- Length :- Variable length. | |- Memory :- List takes more memory than a tuple. Tuple | |- Syntax :- (2,3,4) | |- Immutable :- Elements cannot be changed after creation. | |- Length :- Fixed length. | |- Memory :- It takes less memory than a list.