Dear student,
The solution to the above problem statement in Java programming language is given as below:
Code:
import java.io.*;
import java.util.*;
public class Main
{
public static int countEven(int[] inputArray)//calculates the total number of even integers in array
{
int count=0;//stores number of even numbers
for(int i=0;i<20;i++)
{
if(inputArray[i]%2==0)
{
count++;
}
}
return count;
}
public static int countOdd(int[] inputArray)//calculates the total number of odd integers in array
{
int count=0;//stores number of odd numbers
for(int i=0;i<20;i++)
{
if(inputArray[i]%2!=0)
{
count++;
}
}
return count;
}
public static void printDividedBy5(int[] inputArray)
{
int count=0;//stores the number of integers divisible by printDividedBy5
for(int i=0;i<20;i++)
{
if(inputArray[i]%5==0)
{
System.out.print(inputArray[i]+",");
count++;
}
}
if(count==0)
{
System.out.println("Good bye!");//prints this if no number is divisible by 5
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter 20 numbers between 0 to 100 inclusive of 0 and 100");
int nums[]=new int[20];//array of integers
int space=20;
int index=0;
while(space!=0)//till there is space left in array
{
int entry=sc.nextInt();
if(entry>=0&&entry<=100)
{
nums[index]=entry;
index++;
space--;
}
else
{
System.out.println("Wrong input. Please Enter a number between 0 to 100 inclusive of 0 and 100 ");
continue;
}
}//input done
int numEven=countEven(nums);
int numOdd=countOdd(nums);
System.out.println("Number of Even integers entered: "+numEven);
System.out.println("Number of Odd integers entered: "+numOdd);
printDividedBy5(nums);
}
}
----------------------------------------------------
Output:
I hope the given solution helps clear your doubt.
Don't forget to give it a thumbs up.
Regards
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 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...
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...
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 that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...
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...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
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 {...
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 Code: Complete the method, sumOdds(), below. The method takes in an array of integers, numbers, and returns the sum of all the odd numbers in the array. The method should return 0 if the array contains no odd numbers. For example, if the given array is [12, 10, 5, 8, 13, 9] then the method should return 27 (5+13+9=27). Starter Code: public class Odds { public static int sumOdds(int[] numbers) { //TODO: complete this method } }
Program Description: Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, count odd integers, compute the sum of numbers that are larger than the first number in...