Question

Java prompt: Write a program that receives a 10 by 4 table (40 integers) from the...

Java prompt:

Write a program that receives a 10 by 4 table (40 integers) from the user, all in one line, and fills a two-dimensional array (10 by 4) based on the input (row by row). Then prints the average of every row, as "Row [i] average: [calculated average for row i]" Finally, prints the average of every column, as "Column [j] average: [calculated average for row j]"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//Main.java
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter 40 integers: ");
    int arr[][] = new int[10][4];

    for(int i = 0;i<arr.length;i++){
      for(int j = 0;j<arr[i].length;j++){
        arr[i][j] = scanner.nextInt();
      }
    }

    int sum = 0;
    for(int i = 0;i<arr.length;i++){
      sum = 0;
      for(int j = 0;j<arr[i].length;j++){
        sum += arr[i][j];
      }
      System.out.println("Row ["+(i+1)+"] average: "+(1.0*sum/arr[i].length));
    }

    for(int j = 0;j<arr[0].length;j++){
      sum = 0;
      for(int i = 0;i<arr.length;i++){
        sum += arr[i][j];
      }
      System.out.println("Column ["+(j+1)+"] average: "+(1.0*sum/arr.length));
    }

  }
}


Add a comment
Know the answer?
Add Answer to:
Java prompt: Write a program that receives a 10 by 4 table (40 integers) from the...
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
  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The...

    Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the...

    In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the user to input a size of an array. Create an array of type int. Ask a user to fill the array. Create a functions sortArray() and mostFrequency(). The sortArray() function will sort number into incrementing order. The sorting function must be implemented from scratch and it must not use any function from the library. Feel free to use any sorting algorithm. The program will...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Task 1 : Write a Java program that prompts for and reads 10 integers from the...

    Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.

  • Write a program using C in Microsoft visual studios. Write a function that receives an array...

    Write a program using C in Microsoft visual studios. Write a function that receives an array of integers and the array length and prints one integer per line (Hint: Use \n for a line break). Left align all of the integers and use a field width of 10. Populate an array of 10 elements from the user and pass the array and its length to the function.

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

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