How can I make the numbers in this code right adjusted? a = 4 ; b = 4 ; c = 1 ;
ID: 3646382 • Letter: H
Question
How can I make the numbers in this code right adjusted?a = 4 ;
b = 4 ;
c = 1 ;
x = 2 ;
Root = (-1*b + Math.sqrt( Math.pow(b,2) - 4*a*c)/ 2*a );
CoefficientOfXSquared = (-(b*x+c)/(Math.pow(x,2)) );
CoefficientOfX = (-(a*x+c)-c/x );
Constant = (-(a*Math.pow(x,2)+b*x) );
System.out.println(" Given that: CoefficientOfXSquared = " +a );
System.out.println(" CoefficientOfX = " +b );
System.out.println(" Constant = " +c );
System.out.println(" Root = " +x );
System.out.println(" x = " + Root );
System.out.println(" a = " + CoefficientOfXSquared );
System.out.println(" b = " + CoefficientOfX );
System.out.println(" c = " + Constant );
System.out.println(" " );
Explanation / Answer
please rate - thanks
use printf, set the field size, and number of decimal places
if you message me what you want it to look like, I will fix the code
import java.util.*;
public class main
{public static void main(String[] args)
{double a,b,c,x;
a = 4 ;
b = 4 ;
c = 1 ;
x = 2 ;
double Root = (-1*b + Math.sqrt( Math.pow(b,2) - 4*a*c)/ 2*a );
double CoefficientOfXSquared = (-(b*x+c)/(Math.pow(x,2)) );
double CoefficientOfX = (-(a*x+c)-c/x );
double Constant = (-(a*Math.pow(x,2)+b*x) );
System.out.printf(" Given that: CoefficientOfXSquared = %6.2f " ,a );
System.out.printf(" CoefficientOfX = %6.2f " ,b );
System.out.printf(" Constant = %6.2f " ,c );
System.out.printf(" Root = %6.2f " ,x );
System.out.printf(" x = %6.2f " , Root );
System.out.printf(" a = %6.2f " , CoefficientOfXSquared );
System.out.printf(" b = %6.2f " , CoefficientOfX );
System.out.printf(" c = %6.2f " , Constant );
System.out.printf(" " );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.