Multiple statements not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yappy70
    New Member
    • Dec 2007
    • 1

    Multiple statements not working

    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);
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    (After adding the missing close braces!) Your code runs. There are two println statements and they each output a line of text. If that is not what you get, perhaps you are having trouble with your compiler/IDE. If you are using an IDE, do a rebuild; if you are directly using a compiler, delete the old .class file and compile again.

    Comment

    Working...