How can i code in java using Two-dimensional Arrays
Method to input data from the data file
Method to display the table (Please align columns, but no need to use borders, line separators, etc.)
Method to compute the average of each row and display it
Method to compute the average of each column and display it
Method to compute the overall average

program does NOT require create a user-defined class (reference type). create 3 parallel arrays (one for the names, one for the scores, and one for the deviations) in your main method.
create methods for the input, for the output, for the average,
and for the deviation calculation. These methods will be called from method main.

This is my input file data:
88 90 94 102 111 122 134
75 77 80 86 94 103 113
80 83 85 94 100 111 121
68 71 76 85 96 110 125
77 84 91 98 105 112 119
81 85 90 96 102 109 120

Recommended Answers

All 4 Replies

Hey star100,
It's kind of obvious that your post is a question straight out of a text book. I would recommend giving it a try first.
For the 2D array, the basic idea behind it is that you can store data in a table or a map with coordinates IE

[U]    column 1    |    column 2    |    column 3[/U]
[U]row1|  (0,0)          |  (1,0)       |   (2,0)
row2|  (0,1)          |  (1,1)       |   (2,1)
row3|  (0,2)          |  (1,2)       |   (2,2)[/U]

so first thing you have to do is get your array setup with the appropriate amount of data or the data itself. I am 100% sure the text book you copied your question from has a section on 2D arrays. So give it a go and then post your code if it doesn't work.

PO,

Remember we'd love to help you out as long as you attempt it first.

This is my code.

import java.io.*;
import java.util.*;
import java.util.Scanner;



public class Part2

{ 

    static final int rows = 7;       //this can be set to any number
    static final int columns = 3;    //this can be set to any number

static Scanner console = new Scanner(System.in);
public static void main (String [] args) throws FileNotFoundException

{ 
Scanner inFile = new Scanner (new FileReader("score.txt"));



}

public static boolean inputdata(Scanner inFile,int testScore,StringBuffer studentName)
throws FileNotFoundException

{
if (!inFile.hasNext())
return false;

                     studentName.delete(0,studentName.length());
                      //employeeName.append(inFile.nextLine());
                            testScore.getNum (inFile.nextInt());
                           inFile.nextLine(); //discards CR
            return true;    

 }                          
   public static void printMatrix(int[][] matrix)
    {
        int row, col;


        for (row = 0; row < matrix.length; row++)
        {
            for (col = 0; col < matrix[row].length; col++)
                System.out.printf("%7d", matrix[row][col]);

            System.out.println();
        }
    }
public static void sumRows(int[][] matrix)
    {
        int row, col;
        int sum;

            //sum of each individual row
        for (row = 0; row < matrix.length; row++)
        {
            sum = 0;

            for (col = 0; col < matrix[row].length; col++)
                 sum = sum + matrix[row][col];

            System.out.println("The sum of the elements of row "
                            + (row + 1) + " = " + sum);
        }
    }
  public static void sumColumns(int[][] matrix)
    {
        int row, col;
        int sum;

              //sum of each individual column
        for (col = 0; col < matrix[0].length; col++)
        {
            sum = 0;
            for (row = 0; row < matrix.length; row++)
                sum = sum + matrix[row][col];
            System.out.println("The sum of the elements of column "
                             + (col + 1) + " = " + sum);
        }
    }







 }

Ok, so what is your question then?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.