Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Quadratic
- {
- public static void main(String[] args)
- {
- Scanner scanner = new Scanner(System.in);
- while(scanner.toString() != "NO")
- {
- try
- {
- System.out.println("Enter A");
- double a = scanner.nextDouble();
- scanner.nextLine();
- System.out.println("Enter B");
- double b = scanner.nextDouble();
- scanner.nextLine();
- System.out.println("Enter C");
- double c = scanner.nextDouble();
- scanner.nextLine();
- root(a,b,c);
- System.out.println("It works!");
- }
- catch (IllegalArgumentException oops)
- {
- oops.printStackTrace();
- }
- catch(Exception other)
- {
- other.printStackTrace();
- }
- System.out.println("Do you want to continue ?");
- System.out.println("YES / NO");
- String a1 = scanner.next();
- }
- System.out.println("Exit");
- }
- static double root(double A, double B, double C) throws IllegalArgumentException
- {
- if (A == 0)
- {
- throw new IllegalArgumentException("A can't be zero");
- }
- else
- {
- double disc = B*B - 4*A*C;
- if (disc < 0)
- {
- throw new IllegalArgumentException("Discriminant < zero.");
- }
- return (-B + Math.sqrt(disc)) / (2*A);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement