Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double a = Double.parseDouble(scanner.nextLine());
- double b = Double.parseDouble(scanner.nextLine());;
- double c = Double.parseDouble(scanner.nextLine());;
- double x1, x2;
- double det = (b * b) - (4.0 * a * c);
- double sqrt = Math.sqrt(det);
- DecimalFormat pattern = new DecimalFormat("0.0");
- if(det > 0){
- x1 = (-b - sqrt) / (2*a);
- x2 = -(b - sqrt) / (2*a);
- System.out.print("x1=" +pattern.format((x1))+";"+" ");
- System.out.println("x2=" + pattern.format((x2)));
- }
- else if(det == 0){
- x1=x2=-b / (2*a);
- System.out.print("x1=" + pattern.format((x1))+";"+" ");
- System.out.println("x2=" + pattern.format((x2)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement