`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
import java.util.Scanner;
public class Test{
public static int sum2DArray(int[][] inputArray)
{
int s=0;
for(int i=0;i<inputArray.length;i++)
{
for(int j=0;j<inputArray[0].length;j++)
s+=inputArray[i][j];
}
return s;
}
public static int columnMul(int[][] inputArray,int x)
{
int p=1;
for(int i=0;i<inputArray.length;i++)
p=p*inputArray[i][x-1];
return p;
}
public static int rowMul(int[][] inputArray,int x)
{
int p=1;
for(int i=0;i<inputArray[x].length;i++)
p=p*inputArray[x-1][i];
return p;
}
public static void main(String []args){
System.out.println("Enter 25 elements greater than 0 and
even");
Scanner sc=new Scanner(System.in);
int[][] inputArray=new int[5][5];
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
int num=sc.nextInt();
while(num<=0||num%2==1)
{
System.out.println("Please enter again");
num=sc.nextInt();
}
inputArray[i][j]=num;
}
}
System.out.println("sum2DArray is "+sum2DArray(inputArray));
System.out.println("columnMul is "+columnMul(inputArray,2));
System.out.println("rowMul is "+rowMul(inputArray,3));
}
}
Kindly revert for any queries
Thanks.
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 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...
Assignment: Write a program with each of the following methods. You can assume this program is saved in a file called multiArrays.java. A sample main method and sample output is provided at the end of this section. All arrays created are of integer-type. Write a method to declare, initialize, and populate a two-dimensional array. Using the following header: public static int[ ][ ] declare2D(Scanner scnr) The user will indicate the size of the array. Write a method to declare,...
Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array. Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...
Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers). Prompts the user for a starting number: say 'x' Prompts the user for an ending number: say 'y' Prints out the multiplication table of 'x' up to the number 'y' Sample outputs include: SPECIFIC REQUIREMENTS You must use the following method to load the array: public static void loadArray(int table[ ][ ], int x, int y) You must use the following method to...
Write a program that reads a file containing an arbitrary number of text integers that are in the range 0 to 99 and counts how many fall into each of eleven ranges. The ranges are 0-9, 10-19, 20-29,..., 90-99 and an eleventh range for "out of range." Each range will correspond to a cell of an array of ints. Find the correct cell for each input integer using integer division. After reading in the file and counting the integers, write...
(JAVA) Given an array of unique positive integers, write a function findSums that takes the array input and: 1. Creates a hashtable called “hashT” and inserts all the elements of the input array in the hashtable. 2. Finds pairs of elements in the hashtable whose sum is another element (sum) in the hashtable and print the pairs in the console. 3. Returns another hashtable names “sums” of those sum elements. For example: Input: [1,5,4,6,7,9] Output: [6,5,7,9] Explanation: 6 = 1...
Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y' SPECIFIC REQUIREMENTS 1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to...