1 Reply Latest reply on Mar 26, 2007 2:46 PM by doremifasollatido

    Programming Problem Math.floor

      I'm a beginner programmer using Java version jdk1.5.0_11 and I'm having trouble solving the following problem:

      An application of method Math.floor is rounding a value to the nearest integer. The statement:

      y = Math.floor( x + 0.5 );

      will round the number x to the nearest integer and assign the result to y. Write an application that reads double values and uses the preceding statement to round each of the numbers to the nearest integer. For each number processed, display both the original number and the rounded number.
      Here is what I have so far:

      import java.util.Scanner;

      public class Main
      public static void main( String[] args)
      Scanner input = new Scanner ( System.in );

      System.out.print( "Enter a floating-point value. ");
      double x = input.nextDouble();
      y = Math.floor( x + 0.5 );

      System.out.printf("The original value is %d\n",x);
      System.out.printf("The rounded value is %d\n",y);


      I keep getting the error that it can't find the symbol "y". If anyone can help, I would greatly appreciate it!