Question

Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...

Using import java.util.Random, create a simple java code that populates an array with 10 random numbers (choosing between a range of 20 to 90) and then outputs the largest number.

Homework Answers

Answer #1

ANSWER: Here I am giving you the code and output please like it.

CODE:

import java.util.Random;
public class Main
{
public static int getRandomNumberUsingNextInt(int min, int max) {
Random random = new Random();
return random.nextInt(max - min) + min;
}
   public static void main(String[] args) {
   int arr[]= new int[10];
   for(int i=0;i<10;i++){
   arr[i]=getRandomNumberUsingNextInt(21,91);
  
   }
   int max=arr[0];
   System.out.println("Your array :");
   for(int i=0;i<10;i++){
  
  
   if(arr[i]>max)
   max=arr[i];
   System.out.print(arr[i]+" ");
   }
       System.out.println("\nLargest number:"+max);
   }
}

OUTPUT:

Know the answer?
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
Similar Questions
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using...
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using any looping statement. Store it in a 2-dimensional array. Display all the numbers in a table format. Determine which numbers are odd and which numbers are even (include their array index) need some help with codes
how do i create an array of 65536 elements with random non repeated numbers and it...
how do i create an array of 65536 elements with random non repeated numbers and it is sorted? in java please. thank you
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number....
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number. You have three additional int variables pos, neg, and zero. Your goal is to determine the number of positive, negative, and zeroes in the list of the ten numbers read in.
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Design the logic for a program that allows a user to enter 10 numbers, stores the...
Design the logic for a program that allows a user to enter 10 numbers, stores the numbers in an array, then displays all of the numbers, the largest number, and the smallest.  create a solution algorithm using pseudocode  create a flowchart Need to do flowchart in Raptor and can't get it to do min and max or display the array
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
Using JAVA For this assignment, you will analyze code that uses a file input stream and...
Using JAVA For this assignment, you will analyze code that uses a file input stream and a file output stream. Read through the linked Java™ code. In a Microsoft® Word document, answer the following questions: Could this program be run as is? If not, what is it lacking? Does this program modify the contents of an input stream? In what way? What are the results of running this code? ********************************************** CODE TO ANALYZE  ******************************************************** /********************************************************************** *   Program:   Datasort *   Purpose:   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT