# Math compile error

Greg Neef

Ranch Hand

Posts: 82

posted 12 years ago

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

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

Posts: 399