Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.Math.*;
- public class First {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.println("podaj a");
- double a=sc.nextDouble();
- System.out.println("podaj b");
- double b=sc.nextDouble();
- System.out.println("podaj c");
- double c=sc.nextDouble();
- double delta = (b*b)-(4*a*c);
- if(delta == 0){
- double x1 = (-b)/(2* a);
- System.out.println("jeden pierwiastek: " + x1);
- }
- else if (delta > 0)
- {
- double x1 = (-b+Math.sqrt(delta)) / (2 * a);
- double x2 = (-b-Math.sqrt(delta)) / (2 * a);
- System.out.println("Dwa pierwiastki:" +x1 + "i " +x2);
- }
- else
- {
- double urojona=((Math.sqrt(Math.abs(delta)))/(2*a));
- double rzeczywista=(-b/(2*a));
- System.out.println(rzeczywista+" + "+urojona+"i");
- System.out.println(rzeczywista+" - "+urojona+"i");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement