Question

In: Computer Science

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 and then outputs the largest number.

Solutions

Expert Solution

JAVA PROGRAM

import java.util.*;
import java.util.Random;
public class Main
{
   public static void main(String[] args) {
       Random random = new Random();
       //declaration of array
       int arr[] = new int[10];
       int lar = 0,i;
       //runs the loop
       for(i=0;i<10;i++)
       {
       //generates the random number & stores it in Array
       arr[i] = random.nextInt();
       }
       lar = arr[0];
       //runs the loop to find the largest number in Array
       for(i=0;i<10;i++)
       {
       //checks the conditon
       if(lar<arr[i])
       {
       lar = arr[i];
       }
   }
   //prints the largest number
   System.out.println("Largest number: "+lar);
   }
}


Related Solutions

Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and...
Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and turns them into words and sentences. The code should use the 0 to represent a space between words and 00 to represent a period at the end of a sentence. The 26 letters of the alphabet should be represented in reverse order. In other words, Z is 26 and A is one. In your final product, only the first letter of a sentence should...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
WITH using methods create an array with numbers
IN JAVA  Prompt 3:WITH using methods create an array with numbersint [] number = { 35, 68, 80, 34, 45, 79, 80};Display the numbers in the array using for loopDisplay the sumFind biggest element in the arrayDisplay the numers in the array with index numbersDisplay the numers using for loop in ascending order (sort)
Implement a Factory Design Pattern for the code below: MAIN: import java.util.ArrayList; import java.util.List; import java.util.Random;...
Implement a Factory Design Pattern for the code below: MAIN: import java.util.ArrayList; import java.util.List; import java.util.Random; public class Main { public static void main(String[] args) { Character char1 = new Orc("Grumlin"); Character char2 = new Elf("Therae"); int damageDealt = char1.attackEnemy(); System.out.println(char1.name + " has attacked an enemy " + "and dealt " + damageDealt + " damage"); char1.hasCastSpellSkill = true; damageDealt = char1.attackEnemy(); System.out.println(char1.name + " has attacked an enemy " + "and dealt " + damageDealt + " damage");...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
(Using Random Class) The following UML Class Diagram describes the java Random class: java.util.Random +Random() +Random(seed:...
(Using Random Class) The following UML Class Diagram describes the java Random class: java.util.Random +Random() +Random(seed: long) +nextInt(): int +nextInt(n: int): int +nextLong(): long +nextDouble(): double +nextFloat(): float +nextBoolean(): boolean Constructs a Random object with the current time as its seed. Constructs a Random object with a specified seed. Returns a random int value. Returns a random int value between 0 and n (exclusive). Returns a random long value. Returns a random double value between 0.0 and 1.0 (exclusive). Returns...
Please convert this code written in Python to Java: import string import random #function to add...
Please convert this code written in Python to Java: import string import random #function to add letters def add_letters(number,phrase):    #variable to store encoded word    encode = ""       #for each letter in phrase    for s in phrase:        #adding each letter to encode        encode = encode + s        for i in range(number):            #adding specified number of random letters adding to encode            encode = encode +...
With the code that is being tested is: import java.util.Random; public class GVdate { private int...
With the code that is being tested is: import java.util.Random; public class GVdate { private int month; private int day; private int year; private final int MONTH = 1; private final int DAY = 9; private static Random rand = new Random(); /** * Constructor for objects of class GVDate */ public GVdate() { this.month = rand.nextInt ( MONTH) + 1; this.day = rand.nextInt ( DAY );    } public int getMonth() {return this.month; } public int getDay() {return this.day;...
package week_2; import java.util.Random; import static input.InputUtils.*; /** * Your program should generate a random number...
package week_2; import java.util.Random; import static input.InputUtils.*; /** * Your program should generate a random number between 0 and 9, and challenge the user to guess the number. Write a loop that asks the user to guess a number that the computer is thinking of. Print a success message if they guess correctly. If the user does not guess correctly, tell the user that they need to guess higher, or lower, and ask the user to try again. The user...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them array1 and array 2) Add the two 3Darrays together and then get the average. Save the average on a separate 3D array.(lets name it array3) Then add array1 and array3 then get the average Save the average on a separate 3Darray(lets name it array 4) Then add array2 and array3 then get the average Save the average on a separate 3Darray (lets name it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT