Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code to Copy:
- import java.util.Scanner;
- //Implementation of Scorer class
- public class Scorer {
- //Implementation of main function
- public static void main(String[] args)
- {
- //Declaration of scores as double type array
- //with three rows and columns
- double[][] scores = new double[3][3];
- userInputValues(scores);
- double[] average = computeAverage(scores);
- displaythreerowAverages(average);
- }
- //Implementation of userInputValues function with
- //parameter type double
- public static void userInputValues(double s[][])
- {
- //Declare scanner object
- Scanner inputObject = new Scanner(System.in);
- int k =0,j;
- int rowCount = 1;
- //Iterate the loop
- while(k<s.length)
- {
- j = 0;
- //Iterate the loop
- while(j<s[k].length)
- {
- //Get the input from command line
- System.out.print("value "+rowCount+" : ");
- s[k][j] = inputObject.nextDouble();
- j++;
- rowCount = rowCount + 1;
- }
- k++;
- }
- }
- //Implementation of computeAverage function
- public static double[] computeAverage(double s[][])
- {
- //Declare threerowAverages as type of double
- double[] threerowAverages = new double[s.length];
- //Iterate the loop
- for(int k=0; k<threerowAverages.length; k++)
- {
- threerowAverages[k] = 0;
- int j = 0;
- //Iterate the loop
- while(j<3){
- threerowAverages[k] = threerowAverages[k] + s[k][j];
- j++;
- }
- //calculate the threerowAverages
- threerowAverages[k] = threerowAverages[k] / 3;
- }
- return threerowAverages;
- }
- //Implementation of displaythreerowAverages function
- //with parameter type double
- public static void displaythreerowAverages(double[] threerowAverages)
- {
- //Display statement for first row
- System.out.println("The average of row 1 is: " + threerowAverages[0]);
- //Display statement for second row
- System.out.println("The average of row 2 is: " + threerowAverages[1]);
- //Display statement for third row
- System.out.println("The average of row 3 is: " + threerowAverages[2]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement