File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Math compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math compile error" Watch "Math compile error" New topic
Author

Math compile error

Greg Neef
Ranch Hand

Joined: Jun 16, 2003
Posts: 82
OK, what am I missing? Here is an example (more or less) from kathy and Berts SJCP Study guide.
public class NumberInterrogation
{
public static void main( String [] args )
{
double [] nums = { 10.4, -10.5, Math.PI, 0 } ;
for ( int i = 0; i < nums.length ; i++ )
{
System.out.print( "nums[ i ] = " + nums[ i ] ) ;
System.out.print( " abs = " + Math.abs(nums[i]) ) ;
System.out.print( " ceil = " + Math.ceil(nums[i])) ;
System.out.println( " floor = " + Math.floor(nums[i])) ;
}
}
}
Here is what I get from the compiler
[greg@localhost scjp]$ javac NumberInterrogation.java
NumberInterrogation.java:5: cannot resolve symbol
symbol : variable PI
location: class Math
double [] nums = { 10.4, -10.5, Math.PI, 0 } ;
^
NumberInterrogation.java:9: cannot resolve symbol
symbol : method abs (double)
location: class Math
System.out.print( " abs = " + Math.abs(nums[i]) ) ;
^
NumberInterrogation.java:10: cannot resolve symbol
symbol : method ceil (double)
location: class Math
System.out.print( " ceil = " + Math.ceil(nums[i])) ;
^
NumberInterrogation.java:11: cannot resolve symbol
symbol : method floor (double)
location: class Math
System.out.println( " floor = " + Math.floor(nums[i])) ;
^
./Math.java:5: cannot resolve symbol
symbol : variable PI
location: class Math
double [] nums = { 10.4, -10.5, Math.PI, (double) 0 } ;
^
./Math.java:9: cannot resolve symbol
symbol : method abs (double)
location: class Math
System.out.print( " abs = " + Math.abs(nums[i]) ) ;
^
./Math.java:10: cannot resolve symbol
symbol : method ceil (double)
location: class Math
System.out.print( " ceil = " + Math.ceil(nums[i])) ;
^
./Math.java:11: cannot resolve symbol
symbol : method floor (double)
location: class Math
System.out.println( " floor = " + Math.floor(nums[i])) ;
^
8 errors


SCJP 1.4
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Looks good, compiles and runs fine for me. Is it possible that you have overriden the "Math" class in your class path? Look for a "Math.class" file and, if you have it, get rid of it and try again.
[ September 11, 2003: Message edited by: Wayne L Johnson ]
Greg Neef
Ranch Hand

Joined: Jun 16, 2003
Posts: 82
yep. I was smart enought to realize that calling the dang class Math initially was probably a bad idea but not smart enough to realize that leaving the original Math.class lying around my directory was detrimental.
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math compile error