Math method

can't get it to print the numer I enter

Page 1 of 1

2 Replies - 1211 Views - Last Post: 02 November 2009 - 09:21 PM Rate Topic: -----

#1 acscott03   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 18-September 09

Math method

Post icon  Posted 02 November 2009 - 09:05 PM

I can't get my program to print the numer in (). It is suppose to have the math method print out like this
My program will just print out value. I just don't know what to put in for where the value is. If anyone could help me that'd be great.


Please enter a number: 3.14159
Math.ceil(3.142) = 4.000
Math.abs(3.142) = 3.142
Math.floor(3.142) = 3.000
Math.log(3.142) = 1.145
Math.pow(3.142,3.142) = 36.462
Math.sqrt(3.142) = 1.772

public class acscott_Math
{
		public static void main ( String args[] )
		{

				double value;

				Scanner input = new Scanner ( System.in );

				System.out.print( "\nPlease enter a number: " );
				value = input.nextDouble();

				System.out.print( "\n" );

				System.out.printf( "Math.ceil(value) = %.3f\n", Math.ceil(value));
				System.out.printf( "Math.abs(value) = %.3f\n", Math.abs(value));
				System.out.printf( "Math.floor(value) = %.3f\n", Math.floor(value));
				System.out.printf( "Math.log(value) = %.3f\n", Math.log(value));
				System.out.printf( "Math.pow(value) = %.3f\n", Math.pow(value, value));
				System.out.printf( "Math.sqrt(value) = %.3f\n", Math.sqrt(value));
		}
}


Is This A Good Question/Topic? 1
  • +

Replies To: Math method

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Math method

Posted 02 November 2009 - 09:14 PM

You are just printint the String "value"
you want:

System.out.printf( "Math.ceil(%.3f) = %.3f\n", value, Math.ceil(value));
System.out.printf( "Math.abs(%.3f) = %.3f\n", value, Math.abs(value));
.....
Was This Post Helpful? 0
  • +
  • -

#3 acscott03   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 18-September 09

Re: Math method

Posted 02 November 2009 - 09:21 PM

Thank you!!

This post has been edited by acscott03: 02 November 2009 - 09:40 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1