Results 1 to 4 of 4
  1. #1
    rose is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default need a java code for this question!

    Problem (a) Football Scores - Two Dimensional Arrays

    Declare a multi dimensional array like the one shown to represent the football game scores of 5 football games held between ITB and some other college team. Two columns represent the respective scores for each game:

    ITB Other

    You are required to set up the scores as random numbers between 1 and 5 for each team in each game. Secondly you must output the scores in the manner shown and determine:
    (i) How many games did ITB win
    (ii) How many goals were scored in each game

    Game 1:
    Game 2:
    Game 3:
    Game 4:
    Game 5:


    Sample Output:

    ITB Other Goals Scored This Game

    Game 1: 2 1 3
    Game 2: 3 2 5
    Game 3: 1 2 3
    Game 4: 0 1 1
    Game 5: 1 1 2

    Problem (b)
    Declare a two dimensional array that has 6 rows and 4 columns. Assign random numbers (integers between 1 and 10) to all elements. You are required to find the following:
    The total of all elements
    The totals of each row
    The totals of each column

  2. #2
    Azzia is offline Member
    Join Date
    May 2008
    Location
    Ohio
    Posts
    20
    Rep Power
    0

    Default

    It would probably be best if you attempted the assignment rather than asking someone to do it for you.

  3. #3
    rose is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default

    i have wriiten the code for that question...can u plz check if its right or not...

    class WS3AQ1{
    public static void main(String[]args){
    int myArray[][] = new int[5][2];

    fillArray(myArray);
    // Array is full and changed!"!!! - ref parameter!!!



    processCols(myArray);

    }

    ////////////////////////////////////
    // Procedure to fill the array
    ////////////////////////////////////
    static void fillArray(int a[][]){ // reference parameter = a[][]

    int total =0;
    int wins = 0;
    // Heading outside of any for loop - once off print only
    System.out.print("\tITB\tOther\t\tTotal");

    for(int r=0; r<5; r++) // for r = 0 to 4
    {
    total = 0; // RESET for every column!!
    System.out.println();
    System.out.print("Game " + (r+1) + "\t: ");
    for(int c=0; c<2;c++)
    {
    a[r][c] = (int)(Math.random()*10000)%5+0;
    total = total + a[r][c];
    System.out.print(a[r][c] + "\t");
    }
    if (a[r][0] > a[r][1]) wins++;
    System.out.print("\t" + total);
    }

    System.out.print("\n\n\n");


    System.out.println("\nITB wins " + wins + " games ");

    }
    ///////////////////////////////////////////
    // PROCESS COL BY COL!!!!!
    static void processCols(int a[][]){
    int total;

    System.out.print("\n\n\n\n");

    for(int c=0; c<2; c++)
    {
    total =0; // reset for each col

    for(int r=0; r<5; r++)
    {
    total = total + a[r][c];
    }

    System.out.print("\t" +total);

    }
    System.out.print("\n\n\n\n");



    }


    }
    Last edited by rose; 05-07-2008 at 05:58 PM.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

Similar Threads

  1. Java Question
    By Jay-1.1 in forum New To Java
    Replies: 11
    Last Post: 05-01-2008, 04:04 PM
  2. Java Question, i need to be answered
    By Sunshine in forum New To Java
    Replies: 7
    Last Post: 04-28-2008, 01:00 PM
  3. New Comer, Java C# question
    By lmei007 in forum Advanced Java
    Replies: 0
    Last Post: 02-04-2008, 04:54 PM
  4. Java Pacman question
    By whdbstjr90 in forum New To Java
    Replies: 0
    Last Post: 12-11-2007, 11:28 PM
  5. Java Review Question
    By toad in forum New To Java
    Replies: 1
    Last Post: 10-29-2007, 06:13 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
  •