This program can be used to solve problems related to Quadratic Equations
Code
import java.util.Scanner; class QuadraticCalculator { public static void main(String args[]) { Scanner s=new Scanner(System.in); double a,b,c,quad_dis,quad_11,quad_1,quad_21,quad_2; System.out.println("Enter the value of A"); a=s.nextDouble(); System.out.println("\nEnter the value of B"); b=s.nextDouble(); System.out.println("\nEnter the value of C"); c=s.nextDouble(); quad_dis=b*b-4*a*c; quad_11=(-1*b)+(Math.sqrt(quad_dis)); quad_1=quad_11/(2*a); quad_21=(-1*b)-(Math.sqrt(quad_dis)); quad_2=quad_21/(2*a); int choice;
System.out.println("\n\nWhat do you want to do with the numbers you entered ?\n(1) Calculate Discriminant\n(2) Calculate the values\n(3) Find the nature of roots\n(4) All of the above");
choice=s.nextInt(); switch(choice) { case 1: System.out.println("\nDiscriminant: "+quad_dis); break; case 2: System.out.println("\nValues are: "+quad_1+", "+quad_2); break; case 3: if(quad_dis>0) { System.out.println("\nThe roots are REAL and DISTINCT"); } else if(quad_dis==0) { System.out.println("\nThe roots are REAL and EQUAL"); } else { System.out.println("\nThe roots are IMAGINARY"); } break; case 4: System.out.println("\nDiscriminant: "+quad_dis); System.out.println("\nValues are: "+quad_1+", "+quad_2); if(quad_dis>0) { System.out.println("\nThe roots are REAL and DISTINCT"); } else if(quad_dis==0) { System.out.println("\nThe roots are REAL and EQUAL"); } else { System.out.println("\nThe roots are IMAGINARY"); } break; } System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThank You for using this Calculator"); } }
Output
Link for Download
http://goo.gl/S8OGge
No comments:
Post a Comment