Hello everyone!

I am in the process of creating a program that finds the fourth variable value (a,b,c, or x) within the quadratic formula. I am trying to display my results in combination with what I assign to the other three values. For example, I would want to say:

Given that:

CoefficientOfXSquared = 4.0 (these numbers are for e.x.)

CoefficientOfX = 2.0

TheConstant = 6.0

TheRoot = -1.7777766 (this last value is found by plugging in the other three into the equation).

Basically, I am trying to right align the numbers on the right side of the equal sign, so it would look something like this:

= 4.0

= 2.0

= 6.0

= -1.7777766

i initially thought I could just put some spaces or '\t's in there, but I realized I need to craft in in such a way that the values can be changed and the numbers still be flush with the right side.

Can anybody guide me towards the right direction?

Thanks so much!

tryingtolearn

Code:public class JQuadratic { public static void main(String[] Theory) { double CoefficientOfXSquared, CoefficientOfX, TheConstant, TheRoot; // PROBLEM #1 - SOLVING FOR 'A' VALUE System.out.println("\t\t\t\t Problem #1\n"); CoefficientOfX = 5; TheConstant = 4; TheRoot = 6; CoefficientOfXSquared = (-CoefficientOfX * TheRoot - TheConstant)/(TheRoot * TheRoot); System.out.println( "\t\t\t\t Given that:" ); System.out.println("\t\t CoefficientOfX = " + CoefficientOfX + " and "); System.out.println("\t\t TheConstant = " + TheConstant + " and "); System.out.println("\t\t TheRoot = " + TheRoot + " then"); System.out.println("\t\t CoefficientOfXSquared = " + CoefficientOfXSquared + " \n\n"); // PROBLEM #2 - SOLVING FOR 'B' VALUE System.out.println("\n\n\t\t\t\t Problem #2\n"); CoefficientOfXSquared = 5; TheConstant = 2; TheRoot = 3; CoefficientOfX = (-TheConstant - CoefficientOfXSquared * Math.pow(TheRoot,2))/TheRoot; System.out.println( "\t\t\t\t Given that:" ); System.out.println("\t\t CoefficientOfXSquared = " + CoefficientOfXSquared + " and "); System.out.println("\t\t TheConstant = " + TheConstant + " and "); System.out.println("\t\t TheRoot = " + TheRoot + " then"); System.out.println("\t\t CoefficientOfX = " + CoefficientOfX + "\n\n" ); // PROBLEM #3 - SOLVING FOR 'C' VALUE System.out.println("\n\n\t\t\t\t Problem #3\n"); CoefficientOfXSquared = 67 ; CoefficientOfX = 78 ; TheRoot = 100; TheConstant = -CoefficientOfXSquared * Math.pow(TheRoot, 2) - CoefficientOfX * TheRoot; System.out.println( "\t\t\t\t Given that:" ); System.out.println("\t\t CoefficientOfXSquared = " + CoefficientOfXSquared + " and "); System.out.println("\t\t CoefficientOfX = " + CoefficientOfX + " and "); System.out.println("\t\t TheRoot = " + TheRoot + " then"); System.out.println("\t\t TheConstant = " + TheConstant + " \n\n"); // PROBLEM #4 - SOLVING FOR 'X' VALUE System.out.println("\n\n\t\t\t\t Problem #4\n"); CoefficientOfXSquared = 3; CoefficientOfX = 9; TheConstant = 6; TheRoot = (-CoefficientOfX + Math.sqrt(Math.pow(CoefficientOfX,2) - 4 * CoefficientOfXSquared * TheConstant)) / (2 * CoefficientOfXSquared); System.out.println( "\t\t\t\t Given that:" ); System.out.println("\t\t CoefficientOfXSquared = " + CoefficientOfXSquared + " and "); System.out.println("\t\t CoefficientOfX = " + CoefficientOfX + " and "); System.out.println("\t\t TheConstant = " + TheConstant + " then"); System.out.println("\t\t TheRoot = " + TheRoot + " \n\n"); System.out.println("\n\n\n"); } }

Tweet This+ 1 thisPost To Linkedin