Results 1 to 7 of 7
  1. #1
    aramiky818 is offline Member
    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    Default Array, method to change character places

    hey guys,
    so i came up with this 2d array which prints

    Generation Zero

    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X
    X X X X X X X X X X X X
    X X X X X X X X X X X

    now what i want to do is create a method that goes in the array and replaces the X with an empty space ' ' and fills up the empty space with the letter X, so basically do the opposite of what i have.

    here is the code i got so far:

    public class SecondArray2D
    {
    public static void main(String[]args)
    {


    char [][] array = {

    {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' '},
    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},

    };

    System.out.println(" Generation Zero");
    for (int n=0; n< array.length; n++)
    {
    System.out.println(array[n]);
    }


    }




    }

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

    Default Re: Array, method to change character places

    What is your current question as I don't see one in your post above?

  3. #3
    aramiky818 is offline Member
    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    Default Re: Array, method to change character places

    if you notice what the program prints is something like so,

    Generation Zero
    x x x x x x
    x x x x x
    x x x x x x

    im looking for a method or someway tht i could replace all characters in the array with an empty space and and fill all empty spaces with a character.

    so if
    if Generation zero looks like above,
    i would like Genration one to look like this
    x x x
    x x x x

    the exact oposit,

    of this

    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},

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

    Default Re: Array, method to change character places

    Quote Originally Posted by aramiky818 View Post
    if you notice what the program prints is something like so,

    Java Code:
       Generation Zero
        x  x  x  x  x  x 
          x  x  x  x  x
       x   x  x  x   x  x
    im looking for a method or someway tht i could replace all characters in the array with an empty space and and fill all empty spaces with a character.

    so if
    if Generation zero looks like above,
    i would like Genration one to look like this
    Java Code:
          x  x  x  
         x  x  x  x
    the exact oposit,

    of this

    {' ',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ','X',' ',' '},
    OK, so what have you tried so far, or what ideas do you have for this?

  5. #5
    aramiky818 is offline Member
    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    Default Re: Array, method to change character places

    nothing, im lost. i got stuck and i donno how to get started on next step, which is what i just explained

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

    Default Re: Array, method to change character places

    Well, you need to step through the arrays, and what's the best tool for iterating through an array?

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

    Default Re: Array, method to change character places

    For instance, say you have an array of int and you want to add all the ints up, what would you use to do this?

Similar Threads

  1. Integer value in Character Array
    By AwesomeGuy in forum New To Java
    Replies: 1
    Last Post: 04-09-2011, 08:41 PM
  2. Replies: 0
    Last Post: 04-02-2011, 02:57 AM
  3. Using a character array with html
    By ishdevil in forum New To Java
    Replies: 0
    Last Post: 02-10-2010, 02:01 PM
  4. Replies: 2
    Last Post: 02-24-2009, 05:32 PM
  5. comparing array using character
    By Anseki in forum New To Java
    Replies: 7
    Last Post: 10-03-2008, 08: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
  •