Calculate the maximum of the values for all table cells using a method named arrayMax

computer science

Description

Question 1

Write a Java program that find the maximum of 10 random number (the maximum value is 20) stored in a table. For this:

 

1.   You need fill the table cell using the method generateRandomNb.

2.   Display the values for all table cells

3.   Calculate the maximum of the values for all table cells using a method named arrayMax

4.   Display the average

 

import java.util.Random;

 

public static int generateRandomNb(int max){ 

           int randomInt;

           Random rnum = new Random();

           randomInt=rnum.nextInt(max);

           return randomInt;

      }   

  

For example:

·         To fill an array MyNumbers:  MyNumbers[i]= generateRandomNb(20);

·        To provide the array MyNumbers as argument of method arrayMax:

arrayMax(int[] MyNumbers)

 

Question 2

Create a method arrayMaxBorns which is the enhancement of the method arrayMax of the question 1. This method will find the index of the cell that contains the maximum in an array between the 2 indexes.

For example, for the following table, if I give the indexes 1, 6, the method will return 5 and the maximum is 14, which is the maximum value between myNumber[1] to myNumber[6].


 

 

24

 

 

24

 

3

 

 

3

 

 8

 

 

 8

 

10

 

 

10

 

2

==>

11

 

14

 

 

14

index=5

12

 

 

12

 

1

 

 

1

 

19

 

 

19

 

17

 

 

17

 

 

1.   You need to create the table MyNumbers and fill its cell using the method generateRandomNb as in Question 1.

2.   Display the values for all cells of MyNumbers

3.   Ask the user to give you the index begin and the index end using the Scan class

4.   Create the method arrayMaxBorns. Provide to the method the array and the 2 indexes

5.   Display the maximum


 


Related Questions in computer science category