Hello. I am a college student in a Java class. I am working on an assignment, that I believe my code is correct, but after its compiled and ran I only get values back for the last statement. Any help would be greatly appreciated!
Here is the problem: Math.floor may be used to round a number to a specific decimal place. The statement: y = Math.floor ( x * 10 + 0.5) / 10; rounds x to the tenths position (i.e. first position to the right of the decimal point). Write an application that defines four methods for rounding a number x in various ways:
a:) roundtoInteger (number)
b.) roundtoTenths (number)
c.) roundtoHundredt hs (number)
Here is my code:
public class round
{
// main method begins execution of Java application
public static void main( String args[] )
{
int x; //integer x
double y; //integer y
x = 3;
y = Math.floor ( x * 10 + 0.5) / 10;
System.out.prin tln ("Integer's whole number is: " + y);
y = Math.floor ( x * 100 + 0.5)/100;
System.out.prin tln ("Integer's tenth's place is: " + y);
Here is the problem: Math.floor may be used to round a number to a specific decimal place. The statement: y = Math.floor ( x * 10 + 0.5) / 10; rounds x to the tenths position (i.e. first position to the right of the decimal point). Write an application that defines four methods for rounding a number x in various ways:
a:) roundtoInteger (number)
b.) roundtoTenths (number)
c.) roundtoHundredt hs (number)
Here is my code:
public class round
{
// main method begins execution of Java application
public static void main( String args[] )
{
int x; //integer x
double y; //integer y
x = 3;
y = Math.floor ( x * 10 + 0.5) / 10;
System.out.prin tln ("Integer's whole number is: " + y);
y = Math.floor ( x * 100 + 0.5)/100;
System.out.prin tln ("Integer's tenth's place is: " + y);
Comment