Question

CPS 2231 Chapter 8 Lab 1 Spring 2019 1. Write a class, SumOrRows. The main method will do the following methods: a. Call a me

CPS 2231 Chapter 8 Lab 1 Spring 2019 Note: To prom for (int row o; row < matrix.length , row++) System.out.printin(Enter the

please use eclipse
the sample output is incorrect

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As asked by you, this is the required code.

Thanks for Asking! The output is attached as an image below.

Also, eclipse has been used for this question!

Scanner has been used for input and all the four functions are used with the same argument names and function names as given in the code! Hope you like it! :)

import java.util.*;
public class Program {
   static Scanner sc= new Scanner(System.in);
   public static void main(String[] args) {
       int [][]matrix= createAndFillArray();
       printArray(matrix);
       int[] sums= calcSums(matrix);
       printSums(sums);
   }

   public static int[][] createAndFillArray()
   {
       int a[][]=new int[3][4];
       for(int i=0;i<3;i++)
       {
           System.out.println("Enter 4 column values for row "+(i+1));
           for(int j=0;j<4;j++)
           {
               a[i][j]= sc.nextInt();
              
           }
       }
       return a;
   }
  
   public static void printArray(int[][] matrix)
   {
       for(int i=0;i<3;i++)
       {
           for(int j=0;j<4;j++)
           {
               System.out.print(matrix[i][j]+" ");
              
           }
           System.out.println();
       }
      
   }
  
   public static int[] calcSums(int[][] table)
   {
       int sum[]= new int[3];
       for(int i=0;i<3;i++)
       {
           for(int j=0;j<4;j++)
           {
               sum[i]=sum[i]+table[i][j];
           }
       }
       return sum;
   }
  
   public static void printSums(int[] sums)
   {
       for(int i=0;i<3;i++)
       {
           System.out.println("The sum of row "+i+" is: "+sums[i]);
       }
   }
  
}

Problems | @ Javadoc® Declaration Console X terminated> Program Java Application] CAProgram Files Javaljre1.8.0.131\binljavaw

Add a comment
Know the answer?
Add Answer to:
please use eclipse the sample output is incorrect CPS 2231 Chapter 8 Lab 1 Spring 2019...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The last element in each array in a 2D array is incorrect. It’s your job to...

    The last element in each array in a 2D array is incorrect. It’s your job to fix each array so that the value 0 is changed to include the correct value. In the first array, the final value should be the length of the first array. In the second array, the final value should be the sum of the first value, and the second to last value in the array. In the third array, the final value should be the...

  • //please help I can’t figure out how to print and can’t get the random numbers to...

    //please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...

  • Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right...

    Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()"                                         public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...

  • Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the...

    Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class...

    please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class Chapter9a_FillInTheCode { public static void main(String[] args) { String [][] geo = {{"MD", "NY", "NJ", "MA", "CA", "MI", "OR"}, {"Detroit", "Newark", "Boston", "Seattle"}}; // ------> exercise 9a1 // this code prints the element at row at index 1 and column at index 2 // your code goes here System.out.println("Done exercise 9a1.\n"); // ------> exercise 9a2 // this code prints all the states in the...

  • In Java Please Create A Program For The Following; Please Note: This program should be able...

    In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • Hi I need some help on this lab. The world depends on its successfull compilation. /*...

    Hi I need some help on this lab. The world depends on its successfull compilation. /* Lab5.java Arrays, File input and methods Read the comments and insert your code where indicated. Do not add/modify any output statements */ import java.io.*; import java.util.*; public class Lab5 { public static void main (String[] args) throws Exception { final int ARRAY_MAX = 30; // "args" is the list of tokens you put after "java Project3" on command line if (args.length == 0 )...

  • AP computer science: please do not use other advanced ways to solve this problem, it is...

    AP computer science: please do not use other advanced ways to solve this problem, it is just an AP class in high school. Thank you so much! publie class ArrayMethods public class Array Methods // precondition: anArray is not null. target is an element in the array // postcondition: absolute value of difference between target and average of // precondition: anArray is not null // postcondition: anArray is output anArray is returned. public static void PrintArray (int [0 anArray) public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT