Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define an array, Read values into array, Compute average of all elements of array, Computer Max and Min of elements of array, Print an array,

Define an array, Read values into array, Compute average of all elements of array, Computer Max and Min of elements of array, Print an array, etc.

Consider the following example --

import java.util.Scanner;

public class TestArray {

/** Main method */

public static void main(String[] args) {

final int SIZE = 6;

int[] numbers = new int[SIZE];

Scanner kb = new Scanner(System.in); // kb is the Scanner object name J

// Read all numbers

for (int i = 0; i < numbers.length; i++) {

System.out.print("Enter a number:");

numbers[i] = kb.nextInt(); // we used kb as defined in Scanner object }

//find the average of all numbers

double average = 0.0;

int sum = 0;

for (int I = 0; I < numbers.length; i++) {

sum = sum + numbers[i];

}

if (numbers.length != 0) average = (double) sum / numbers.length;

//write code here to print average value here

// Find the largest

int max = numbers[0];

for (int i = 1; i < numbers.length; i++) {

if (numbers[i]> max)

max = numbers[i];

}

//write code here to print max value here similarly compute min and print

// Find the number of occurrences of the largest number

int count = 0;

for (int i = 0; i < numbers.length; i++) {

if (numbers[i] == max) count++;

}

// Print the result

System.out.println("The array values are shown below ";

for (int i = 0; i < numbers.length; i++) {

System.out.println( numbers[i]);

}

System.out.println( " The largest number is " + max) ;

System.out.println(" The occurrence count of the largest number "

+ "is " + count) ;

System.out.println( " That is all Folks!! J ");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago