Results 1 to 12 of 12
  1. #1
    java008 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Smile code using array

    hi

    I have a project and I want some one to help me to do it with java language

    Implement an array, to implement a game name ArrayHunt. Define the maximum size of the array. Insert elements into the array. Sort the elements ascending. Then search for any one item (specify in the code) and display the output whether the item is found or not


    thanx

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Post your code, all compiler/error messages you're getting, a complete description of how the actual behaviour differs from the desired behaviour, and ask an actual question.

    FYI, we will not do this for you.

  3. #3
    java008 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    i did the code but their are some mistake in it
    i don't want you to solve it for me but to help me . i am a new student and i am learning java .

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    if you did the code and saw mistakes post the code and error message you get so we know where to help you.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    i did the code but their are some mistake in it
    i don't want you to solve it for me but to help me . i am a new student and i am learning java .
    Most of us will be far better at helping you to solve your mistakes if we can actually see the mistakes. As posted above several times, do yourself a favor and post your code and the errors.

  6. #6
    java008 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    this is my first part code.
    1- array with size
    2- insert elements to it
    3- sort it in sanding order ( this part i did know how to do it)
    -----------------------------------------------------
    Java Code:
    import java.util.Scanner;
    
    class ArrayHunt
    {
        public static void main(String[] args) 
        {
            
                
            int[] list=new int[5];
            int i;
            
            
            
            System.out.println("Please Enter number of elements:");
            
            Scanner input= new Scanner(System.in);
            
            for( i=0; i<list.length;i++) 
            {
            list[i] = input.nextInt() ;
        }
            
            ArrayHunt objTest = new ArrayHunt();
            objTest.methodTest(list);
        }
             public void methodTest(int[] value)
             {
                 
                
                for(int i=0; i < value.length; i++)
                {
                    
               
                
                 System.out.println("the Number in ascending order: "  + value[i]+".");
                 
                }
                
            }
        }

  7. #7
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    What is "sanding order"?
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  8. #8
    java008 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    sorry I mean in ascending order

  9. #9
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Array has a sort method that will auto sort in ascending order. If you required to do it manually think about how you would do this on paper. First you need to set a low value. then traverse through the array comparing the current value to that low value. If current value is less then low value then you replace low value with current value and repeat the process.

    Fyi your going to need a second array or a swap method to switch numbers in your array.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  10. #10
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    449
    Rep Power
    6

    Default sorry

    sorry,
    i could not be able to understand properly.

  11. #11
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    I don't see any attempt at sorting.

    See the API docs for the class "Arrays" for a sort method, or, if you must do it manually, an easy way is to use a while loop and a for loop.

    Run the for loop over the array, comparing the elements (one to the one that comes after it) swapping their positions when the first is larger, and keep doing it until no numbers change positions (the while loop).

    At least try.

  12. #12
    java008 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 7
    Last Post: 04-28-2008, 04:28 AM
  2. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  3. please i need the code of comparing these two array lists.
    By raj reddy in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 04-18-2008, 07:42 AM
  4. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 10:12 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 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
  •