Results 1 to 9 of 9
  1. #1
    fegiflu is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default Help with removing somthing once inputed.

    This is my code, but i want to add a Remove function, so once you enter in a number, you can remove it from the Fill list.
    the ;;) is suppose to be ;; and )

    public class SimpleSearchableList {

    private static String[] List = new String[25];
    private static int Size; unavailable


    public static void main(String[] args)
    {
    String Cmd;

    for(;;) {
    Menu();
    System.out.print("Command: ");
    Cmd = SimpleIO.inputString();

    if(Cmd.equals("Quit"))
    break;
    else if(Cmd.equals("Fill"))
    FillList();
    else if(Cmd.equals("Remove"))
    RemoveList();
    else if(Cmd.equals("Search"))
    SearchList();
    else if(Cmd.equals("Show"))
    ShowList();
    }

    }



    public static void Menu()
    {
    System.out.println("Choices....................... ...........");
    System.out.println("\tFill the list");
    System.out.println("\tRemove List");
    System.out.println("\tShow the list");
    System.out.println("\tSearch the list");
    System.out.println("\tQuit");
    System.out.println(".............................. ...........");
    }


    public static void FillList()
    {
    int Count;

    for(Count = 0 ; Count < List.length ; Count++)
    {
    System.out.print("Enter: ");
    List[Count] = SimpleIO.inputString();
    if(List[Count].equals("Stop"))
    break;
    }

    Size = Count;
    }






    public static void SearchList()
    {
    String KeyValue;
    boolean NotFoundFlag;
    int K;

    System.out.println("Enter Names Below, Stop To Quit");

    while(true)
    {
    System.out.print("Enter: ");
    KeyValue = SimpleIO.inputString();
    if(KeyValue.equals("Stop"))
    break;

    NotFoundFlag = true;

    for(K = 0 ; K < Size ; K++)
    if(List[K].equals(KeyValue)) {
    NotFoundFlag = false;
    System.out.println(List[K] + " found");
    }

    if(NotFoundFlag)
    System.out.println(KeyValue + " Not Found");
    }
    }


    public static void ShowList()
    {
    int K;

    for(K = 0 ; K < Size ; K++)
    System.out.println("List[" + K + "] = " + List[K]);
    }
    }

  2. #2
    momo97 is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    One thing you can do is to make a new array without the value that you enter for removal, and then show the new array.

  3. #3
    fegiflu is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default

    umm i don't really understand. do you have a code to show me?

  4. #4
    fegiflu is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default

    >.< can anyone help?

  5. #5
    fegiflu is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default

    *bump* i really need help with this please

  6. #6
    levent Guest

    Default

    You are using arrays. You can not remove an element from an array. You can only change its value.

    If you really want to remove an element in an easy way, then use ArrayList or a Vector instead of array. But if you still want to use arrays, you will need to recreate the new array without the element removed as momo97 told.

  7. #7
    fegiflu is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default

    >.< how would you that?

  8. #8
    levent Guest

    Default

    Try searching google before asking something!! Once you have some basic knowledge and try some solutions yourself, you can ask your question. In that way, you can learn and also get more answers! Just a suggestion..

  9. #9
    momo97 is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    burned fegiflu!!, but it's ok, try this:

    public void removeElementAt(int removal Index) {
    for(int i = removalIndex; i < last; i++)
    list[i] = list[i+1];
    last--;
    }
    This shifts all elements up one so when you tell the program to remove an object, it shifts all spots up one so that spot is cleared and thus you have a remove function.
    Good Luck!

Similar Threads

  1. Averages of user inputed values (Need Help)
    By Zebra in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 01:51 PM
  2. image removing
    By Triss in forum New To Java
    Replies: 3
    Last Post: 01-20-2008, 08:27 PM
  3. Removing characters
    By kDude in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 02:38 AM
  4. removing duplicates from arrays
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 06:11 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:35 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
  •