Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 13th, 2006, 05:48 PM
Registered User
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Very, very introductory question...

Hi there -- I am trying to follow through the Wrox book "Beginning Java 2, Version 5," despite the fact that it is largely aimed at PCs and I am on a Mac...as well as the fact that I cannot install JDK 5 because I am on OSX 10.3.9, which only allows up to SDK 1.4!

I was attempting to compile a program which imports two math classes using this basic form: "import static java.lang.Math.sqrt" and also Math.ceil ....

I am compiling and editing them using XCode.

But for some reason these statements does not work. I know that I am typing them correctly, and in fact when I take away the "static" element of the import statement, it reduces the errors produced from 5 to 2, but there are still those two errors because allegedly java.lang.Math.sqrt and .ceil cannot be found!

When I import Math.*, that seems to work fine, but when I make a call to the sqrt or ceil classes, there is an error. Why would these functions not be in java.lang.Math.* ?? Surely sqrt and ceil are not new additions from 1.4 to 5??

Thanks for any help!
Old February 13th, 2006, 06:46 PM
Registered User
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

okay...i modified it so that i didn't start the code with the offending statement, "import static java.lang.Math.sqrt" -- instead, i made a call to java.lang.Math.sqrt from WITHIN the code...somehow THIS works, even though attempting to import it at the top of the code gives me the error "<identifier> expected." why would this be???

also, in the original code, there is a line: "for(long n : primes)" which does not compile when i try it. the error message points to that line and says "; expected." whaaa? i replaced it with for(int i = 0; i < primes.length; i++), which does the same thing, but i am perplexed as to why the original line wouldn't have worked.

please help!

here is the code as i have MODIFIED it:

public class MorePrime {
    public static void main(String[] args) {
        long[] primes = new long[20];
        primes[0] = 2L;
        primes[1] = 3L;
        int count = 2;

        long number = 5L;

        for( ; count < primes.length; number += 2L) {
            long limit = (long)java.lang.Math.ceil(java.lang.Math.sqrt((dou ble)number));

            for(int i = 1; i < count && primes[i] <= limit; i++) {
                if(number%primes[i] == 0L) {
                    continue outer;
            primes[count++] = number;

        for(int i = 0; i < primes.length; i++) {

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of Python in Introductory Web Programming Clas szathmar Python 2 April 17th, 2006 02:07 PM
1 More question!! (me think!) Mantis MySQL 2 March 8th, 2005 08:26 AM
Need some introductory material on MPEG and DVD shim Visual C++ 1 January 15th, 2004 09:44 AM
Question stu9820 ASP.NET 1.0 and 1.1 Basics 6 October 2nd, 2003 10:35 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.