Help on Javascript project


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Help on Javascript project

  1. #1
    Join Date
    Jul 2006
    Location
    Illinois
    Posts
    3

    Unhappy Help on Javascript project

    I need to write a small project for a class I am taking. The assignment is listed below. I am total confused with this one. Can someone help me in the right direction on this one. I am new to java so please keep it basic. Thanks.


    Write a method, removeAll, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete all occurrences of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size will be reduced.) You may assume that the array is unsorted.

  2. #2
    Join Date
    Jul 2006
    Location
    Illinois
    Posts
    3
    Here is what I have put together so far. I can get it to remove one instance of a number but not all instances. Please help.





    import java.io.*;

    import java.util.*;

    public class A5BO2552780
    {
    static BufferedReader keyboard = new
    BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException
    {
    int[] list = new int[20];


    IntClass length;

    int item;

    StringTokenizer tokenizer;


    System.out.println("Enter 10 numbers seperated by a space");

    tokenizer = new StringTokenizer(keyboard.readLine());

    for(int i = 0; i < 12; i++)
    list[i] = Integer.parseInt(tokenizer.nextToken());

    length = new IntClass(12);

    print(list, length.getNum());

    System.out.print("Enter the number to remove: ");
    System.out.flush();
    item = Integer.parseInt(keyboard.readLine());
    System.out.println();

    removeAll(list,length,item);

    print(list, length.getNum());
    }

    public static void removeAll(int[] list, IntClass len, int removeAll)
    {
    int i;

    int loc = 0;
    boolean found = false;


    if(len.getNum() == 0)
    System.out.println("List is empty cannot delete number");
    else
    {
    for(i = 0; i < len.getNum(); i++)
    if(removeAll == list[i])
    {
    found = true;
    loc = i;
    break;
    }

    if(found)
    {
    for(i = loc + 1; i < len.getNum(); i++)
    list[i-1] = list[i];

    len.setNum(len.getNum() - 1);
    }
    else
    System.out.println(removeAll + " is not a number in your list");
    }
    }

    public static void print(int[] list, int len)
    {
    for(int i = 0; i < len; i++)
    System.out.print(list[i] + " ");
    System.out.println();
    }
    }
    Last edited by titan; 07-25-2006 at 03:02 PM.

  3. #3
    Join Date
    Jul 2006
    Location
    Illinois
    Posts
    3
    Bump. Any help please.

  4. #4
    Join Date
    Mar 2004
    Posts
    635
    First of all, this isn't javascript, its java. (very different)
    Second, please use code tags. Looking at unindented code is a headache.

    I'm not sure what IntClass is, but length is nothing more than an integer value.

    Is the method suppose to return a new array with the elements removed?

    Easiest way:

    1. Loop through the array and count how many instances of "removeAll" there are.
    2. Create a new array of the old array's size minus the number of instances you found.
    3. Loop back through the array and copy each element from the old array to the new array if it isn't equal to "removeAll".

  5. #5
    Join Date
    Nov 2007
    Posts
    2

    Help with Java Project..



    Taking this class too and need help as well. Anybody???? See project information below.
    Thanks,
    Dcc

    Write a method, removeAll, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete all occurrences of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size will be reduced.) You may assume that the array is unsorted.

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 01:00 AM
  2. Good Editorial by Russell Jones
    By Robert G in forum .NET
    Replies: 84
    Last Post: 02-08-2001, 03:38 PM
  3. Replies: 0
    Last Post: 09-13-2000, 11:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center