2D-Arrays:Keep columns, while changing all other values

Discussion in 'Java' started by John Inge =?UTF-8?B?RWxsaW5nc8OmdGVy?=, Mar 20, 2006.

  1. How do I do this??

    I have a table [j] that are filled with random integers on each round of
    a loop, but for a certain user input I want to keep column[n] while all
    other numbers are changed.

    I guess this is quite easy, but I just can't seem to figure it out.

    Thanks in advance,
    John Inge E


    If to any help, this is the code for filling the table with integers:
    (some norwegian words in there, sorry about that)


    for (int column = 0; column < antRader; column++) {
    radNr = radNr+1;
    System.out.print("\t L" + radNr + " | ");

    for (int row = 0; row < (antRader); row++) {
    tabell[column][row] = ((int)(Math.random()*(antRandom)+1));
    System.out.print(tabell[column][row]+" - ");
    }
    }
     
    John Inge =?UTF-8?B?RWxsaW5nc8OmdGVy?=, Mar 20, 2006
    #1
    1. Advertising

  2. Hi John Inge,

    >I guess this is quite easy, but I just can't seem to figure it out.


    yes it's very easy. Just test the column number before entering the
    inner for-loop:

    if (column != n) {
    // put your inner loop here
    }

    cu
    Dirk
     
    Dirk Michaelsen, Mar 20, 2006
    #2
    1. Advertising

  3. John Inge =?UTF-8?B?RWxsaW5nc8OmdGVy?=

    Roedy Green Guest

    On Mon, 20 Mar 2006 12:26:03 +0100, John Inge Ellingsæter
    <> wrote, quoted or indirectly quoted someone
    who said :

    >tabell[column][row] = ((int)(Math.random()*(antRandom)+1));


    there are much better ways of doing random numbers. See
    http://mindprod.com/jgloss/pseudorandom.html

    Your question amounts to how do you loop through just the elements you
    want to change. If you can't solve that, try a loop that goes through
    everything, and decided on a case by case basis whether to make the
    change. Once you have that code working, your brain might clue into
    how to code the efficient version. Just eliminate the wasteful parts
    of the loop a bit at a time.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    How to keep a Tkinter-Dialog on top of all other windows?

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jul 2, 2003, in forum: Python
    Replies:
    1
    Views:
    584
    Joe Fromm
    Jul 2, 2003
  2. Jeff Epler
    Replies:
    0
    Views:
    617
    Jeff Epler
    Jul 2, 2003
  3. chris
    Replies:
    0
    Views:
    343
    chris
    Oct 13, 2006
  4. dmitrey
    Replies:
    4
    Views:
    1,925
  5. Philipp
    Replies:
    21
    Views:
    1,181
    Philipp
    Jan 20, 2009
Loading...

Share This Page