Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- public class DecimalFormatt{
- public static void main(String args[]){
- int a,b,c;
- double discriminant, root1, root2;
- Scanner read = new Scanner(System.in);
- System.out.println("Enter the coefficient of x squared: ");
- a = read.nextInt();
- System.out.println("Enter the coefficient of x: ");
- b = read.nextInt();
- System.out.println("Enter the constant: ");
- c = read.nextInt();
- discriminant = Math.pow(b,2)-(4*a*c);
- root1= ((-1*b)+Math.sqrt(discriminant))/(2*a);
- root2= ((-1*b)-Math.sqrt(discriminant))/(2*a);
- DecimalFormat fmt = new DecimalFormat("0.###");
- System.out.println("Root1: "+ fmt.format(root1));
- System.out.println("Root2: "+ fmt.format(root2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement