Question

In Java. Make a multi dimension array of 2 rows and 5 columns. Put 10 random...

In Java. Make a multi dimension array of 2 rows and 5 columns. Put 10 random whole numbers into the multi dimension array. Find the smallest number in the array. Search the array for odd numbers and display them along with their position in the array.

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

Random2DArray.java

import java.util.Random;

public class Random2DArray {

public static void main(String[] args) {

int arr[][] = new int[2][5];

Random r = new Random();

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

for(int j=0;j<arr[i].length;j++) {

arr[i][j] = r.nextInt(1000) + 1;

}

}

int min = arr[0][0];

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

for(int j=0;j<arr[i].length;j++) {

if(min > arr[i][j]) {

min = arr[i][j];

}

}

}

System.out.println("Smallest number is "+min);

System.out.println("Odd numbers are:");

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

for(int j=0;j<arr[i].length;j++) {

if(arr[i][j] % 2 != 0) {

System.out.println("arr["+i+"]["+j+"] = "+arr[i][j]);

}

}

}

}

}

Output:

Smallest number is 34
Odd numbers are:
arr[0][1] = 883
arr[1][2] = 305
arr[1][3] = 143

Add a comment
Know the answer?
Add Answer to:
In Java. Make a multi dimension array of 2 rows and 5 columns. Put 10 random...
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
  • Write a Java program that does the following. a. Declare an integer 2D array with 5...

    Write a Java program that does the following. a. Declare an integer 2D array with 5 rows and 5 columns. b. Initialize the array's elements to random integers between 1 and 10 (inclusive). c. Display all the elements in the 2D array as a table of rows and columns. d. Display the row index and column index of all the even integers in the 2D array. e. Display the sum of first row's elements.

  • make an array of 3 rows and 5 columns with integers. choose the integers by hand....

    make an array of 3 rows and 5 columns with integers. choose the integers by hand. Print out the original array with the integers. Next print out the array in 1) hexadecimal and then in 2) ASCII characters.

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • Use basic java for this after importing PrintWriter object You will make a simple Magic Square...

    Use basic java for this after importing PrintWriter object You will make a simple Magic Square program for this Java Programming Assignment. Carefully read all the instructions before beginning to code. It is also required to turn in your pseudocode or a flowchart along with this program. Here are the instructions: At the beginning of the program, briefly describe to the user what a Magic Square Matrix is (described further on), and then allow them to enter “start” to begin...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the...

    In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the user to input a size of an array. Create an array of type int. Ask a user to fill the array. Create a functions sortArray() and mostFrequency(). The sortArray() function will sort number into incrementing order. The sorting function must be implemented from scratch and it must not use any function from the library. Feel free to use any sorting algorithm. The program will...

  • IN JAVA Read the runners data file into arrays. ONE string array and ONE 2-dimension array....

    IN JAVA Read the runners data file into arrays. ONE string array and ONE 2-dimension array. Each runner has 8 pieces of data, which includes name, and how much they ran for each of 7 days. Print out the raw data in columns. Below the raw data, print out the total miles ran for all of the runners. THIS IS TXT FILE : Keith 10 8 4 5 12 3 2 Anna 9 8 7 6 5 12 13 Derick...

  • utilizing r, how do you do this function? Make a 2 dimensional array of normally distributed...

    utilizing r, how do you do this function? Make a 2 dimensional array of normally distributed random numbers in R with 20 rows and 2 columns Use array(x , dim = c(20, 2)), make sure that the vector, x, has the correct number of observations to match the dimensionality, namely 40 (20 x 2)

  • Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5...

    Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5 digits. Of those numbers give me the following information: - Mean , Mode, Median, Range. - Five times, ask the user for a number within the range (from above) and record the time to find the number in the range. (Loop count) 2. Using a any sort algorithm, build sorted 2D array of random numbers (1 TO 5 digits ) with the x direction...

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
Active Questions
ADVERTISEMENT