• 09-07-2013, 11:05 PM
Lupita1
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:
Attachment 5504
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.
:smash: :frusty: :(sweat):
• 09-08-2013, 01:09 AM
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.
• 09-08-2013, 01:33 AM
Lupita1
Quote:

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.