JAVA WEEK1(A)
/*

Week1 : a) Write a Java program that prints all real solutions to the quadratic
equation ax2 + bx + c = ...
Upcoming SlideShare
Loading in...5
×

Java Week1(A) Notepad

241

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
241
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Week1(A) Notepad

  1. 1. JAVA WEEK1(A) /* Week1 : a) Write a Java program that prints all real solutions to the quadratic equation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminant b2 -4ac is negative, display a message stating that there are no real solutions. */ public class Quadratic { public static void main(String args[]) { double a,b,c,root1,root2; a=3.0; b=4.0; c=2.0; if((b*b-4*a*c)==0) { System.out.println("n ROOTS ARE EQUAL"); root1=-b/(2*a); System.out.println("n root "+root1); } if((b*b-4*a*c) > 0) { root1=-b+Math.sqrt(b*b-4*a*c)/(2*a); root2=-b-Math.sqrt(b*b-4*a*c)/(2*a); System.out.println("nROOTS ARE REAL:n"); System.out.println("n root1 "+root1+"n root2 "+root2); } else System.out.println("n Imaginary Roots."); } } // End of Class Page 1

Ă—