Question

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

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

`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));
  
}
}

.Execute > Share Source File STDIN 1.lı Result $javac Test.java return s; } Sjava -Xmx128M -Xms 16M Test public static int co

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
In Java Write a program that reads an arbitrary number of 25 integers that are positive...
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
  • 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 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    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...

  • Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers)....

    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 which: 1. Prints out the Multiplication Table for a range of numbers (positive...

    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...

  • This is a Java program Write a program that reads an unspecified number of integers, determines...

    This is a Java program Write a program that reads an unspecified number of integers, determines home many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number to 2 decimal places. System.out.println(countPositive); System.out.println(countNegative); System.out.println(total); System.out.printf("%.2f",total * 1.0 / count); Assume inputs are always integer [-912985158, 912985158] and ends with 0. Input 1 2 -1 3...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    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...

  • Write a program that reads a file containing an arbitrary number of text integers that are...

    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...

  • Write a program that reads a sequence of integers into an array and that computes the...

    Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....

  • Write a Java program that reads a 1D array of integers from standard input and returns...

    Write a Java program that reads a 1D array of integers from standard input and returns it.

  • Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from...

    Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...

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