Results 1 to 7 of 7
  1. #1
    DC12 is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default Help! 1 error...

    import java.util.Arrays;
    import java.util .Scanner;

    /**
    This program demonstrates the linear search algorithm.
    */
    public class LinearSearcherTest
    {
    public static void main(String[] args)
    {
    int[] a = ArrayUtil.randomIntArray(20, 100);
    System.out.println(Arrays.toString (a));
    LinearSearcher searcher = new LinearSearcher(a);
    Scanner in = new Scanner(System.in);

    boolean done = false;
    while (!done)
    {
    System.out.print("Enter number to search for, -1 to quit: ");
    int n = in.nextInt();
    if (n == -1)
    done = true;
    else
    {
    int pos = searcher.search(n);
    System.out. println("Foundinposition" + pos);
    }
    }
    }
    }

    cannot find symbol
    symbol : variable ArrayUtil
    location: class LinearSearcherTest
    int[] a = ArrayUtil.randomIntArray(20, 100);
    ^
    1 error

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,414
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by DC12 View Post
    cannot find symbol
    symbol : variable ArrayUtil
    location: class LinearSearcherTest
    int[] a = ArrayUtil.randomIntArray(20, 100);
    ^
    1 error
    As the compiler says: it can't find an ArrayUtil class (there isn't one in the core class distribution). If you have one make your classpath variable refer to it.

    kind regards,

    Jos

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    10

    Default

    Hmm I'd use other words than the compiler, but that class is not part of the SE API.

    EDIT: What Jos said.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    DC12 is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    I have this to go with it aswel, its just soooo confusing :S

    /**
    A class for executing linear searches through an array.
    */
    public class LinearSearcher
    {
    /**
    Constructs the LinearSearcher.
    @param anArray an array of integers
    */
    public LinearSearcher(int[] anArray)
    {
    a = anArray;
    }

    /**
    Finds a value in an array, using the linear search
    algorithm.
    @param v the value to search
    @return the index at which the value occurs, or -1
    if it does not occur in the array
    */
    public int search(int v)
    {
    for (int i = 0; i < a.length; i++)
    {
    if (a[i] == v)
    return i ;
    }
    return -1;
    }
    private int[] a;
    }

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,414
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by DC12 View Post
    I have this to go with it aswel, its just soooo confusing :S
    Yes, that's another class you're using but as you can see it isn't the ArrayUtil class. Have you written the code yourself?

    kind regards,

    Jos

  6. #6
    DC12 is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    yeah my friend and I wrote it, I have a very basic understanding of Java always seem to make mistakes!

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,414
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by DC12 View Post
    yeah my friend and I wrote it, I have a very basic understanding of Java always seem to make mistakes!
    So you must have at least three classes: LinearSearcher, LinearSearcherTest and ArrayUtil and none of them have a package definition. They should all be stored in the same directory. Go to that directory and do:

    Java Code:
    javac -cp . *.java
    kind regards,

    Jos

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  2. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  3. Replies: 1
    Last Post: 10-26-2009, 05:38 PM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •