1. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

Java Code:
```public class JProgramTwo
{
public static void main(String[] UpRight)
{

//DECLARE VARIEBLES and ASSIGNNING VALUES!
int Radius, Height, Edge, Lenght, Width, SideA, SideB, SideC, A, B, C, D, E, F, VSph, VCyl, VCub, VBox, Alg1, Alg2, ATri ;
Radius = 5; //this is for the sphere.
Height = 4; //use this one for the volume of the cylinder.
Edge   = 6; //Use this for the volume of the cube.
Lenght = 3; //box.
Width  = 7; //box.
Height = 8; //box.
SideA  = 6; //triangle side.
SideB  = 6; //triangle side.
SideC  = 1; //triangle side.
A      = 8; //fractions
B	   = 3; //fractions
C      = 4; //fractions
D      = 2; //fractions
E      = 1; //fractions
F      = 9; //fractions

VCub   = Edge*Edge*Edge;
VBox   = Lenght*Width*Height;
Alg1   = 1.0*(A*B + C)/(D + E*F);
Alg2   = 1.0*(A + B)/(C + D);
ATri   = 0.25*Math.sqrt( (SideA+SideB+SideC)*(SideB+SideC-SideA)*(SideA+SideC-SideB)*(SideB-SideC+SideA) );

//THE VOLUME OF THE SPHERE!
System.out.format("The volume of a sphere with given Radius                = " + VSph + "\n\n");
//cylinder
System.out.format("The volume of the cylinder with given Radius and Height = " + VCyl + "\n\n");
//CUBE!
System.out.format("The volume of a cube with a given Edge                  = " + VCub + "\n\n");
//BOX
System.out.format("The volume of the box with given Lenght, Width, Height  = " + VBox + "\n\n");
//ALGEBRAIC EXPRESSioNS
System.out.format("The expression (AB+C)/(D+EF)                            = " + Alg1 + "\n\n");
System.out.format("The expression  (A+B)/(C+D)                             = " + Alg2 + "\n\n");
//TRIANGLE!
System.out.println("The area of the triangle with three given sides        = "+ ATri  + "\n\n\n\n\n\n\n" );

}
}```
//output:

This output displays the numbers to 12+ decimal places. Please, please help me. I have worked on this for 12 hours and I have not gotten the desired results. The numbers must have three decimal places only and they must be right-justified. Please help me.

2. Member
Join Date
Sep 2013
Posts
4
Rep Power
0

Check the API documentation for String.format() and follow the link to the explanation of the format string. Although there is more than one way, the easiest for you is probably to convert your value to a string and then use the format() method.

3. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

Originally Posted by agillator
Check the API documentation for String.format() and follow the link to the explanation of the format string. Although there is more than one way, the easiest for you is probably to convert your value to a string and then use the format() method.

4. Member
Join Date
Sep 2013
Posts
4
Rep Power
0

I think no one is going to do your homework for you although people are willing to point you in the right direction. If you look at String (Java 2 Platform SE 5.0) you will easily see how to create a string and then you can see the explanation for the format method as I suggested.

5. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,838
Rep Power
10

System.out is an instance of PrintStream. So check the PrintStream API to see how to use format. You are not using it correctly. It is absolutely critical that you learn to read and understand the API documentation. Otherwise you will definitely struggle learning Java.

Regards,
Jim