1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
timama [110]
3 years ago
8

Write a program to initialize an ArrayList of Strings and insert ten words. Then, using Math.random, print two different Strings

from the list. The two string must be different, you will need to check that before printing them. Paste your program into the code-runner box below and press run. For this activity, the words you use do not matter, but the values in the ArrayList should not contain any whitespace. Every time you call main, it should print a different pair of values from the list. Write your code in a class named Lesson_12_FastStart
Computers and Technology
1 answer:
mel-nik [20]3 years ago
3 0

Answer:

  1. import java.util.ArrayList;
  2. import java.util.Random;
  3. public class Main {
  4.    public static void main(String[] args) {
  5.        ArrayList<String> arrStr = new ArrayList<String>(10);
  6.        arrStr.add("Apple");
  7.        arrStr.add("Banana");
  8.        arrStr.add("Cat");
  9.        arrStr.add("Dog");
  10.        arrStr.add("Elephant");
  11.        arrStr.add("Fox");
  12.        arrStr.add("Good");
  13.        arrStr.add("Home");
  14.        arrStr.add("Icecream");
  15.        arrStr.add("Jaspel");
  16.        Random rand = new Random();
  17.        int n1 = rand.nextInt(10);
  18.        int n2 = rand.nextInt(10);
  19.        while(n1 == n2){
  20.            n2 = rand.nextInt(10);
  21.        }
  22.        System.out.println(arrStr.get(n1));
  23.        System.out.println(arrStr.get(n2));
  24.    }
  25. }

Explanation:

The solution code is written in Java.

Firstly, create an array list and set 10 strings to the array list (Line 7-17).

Use random nextInt method to generate a number between 0-9 as index (Line 19-21).

While the first random number and the second random number is equal, find a new random random (Line 22-24).

At last print out the first random string and second random string using the n1 & n2 as index to extract the string items from the array list (Line 26-27).

You might be interested in
Which function can be used to insert the current date into a spreadsheet?
VladimirAG [237]

Answer:

im pretty sure it MM/DD/YYYY

Explanation:

3 0
3 years ago
If the user enters 26 what is output? _____________
MArishka [77]

Please write the whole question, is it asking for the function that requests user input?

3 0
3 years ago
Given the following word addresses: 3, 180, 43, 2,191, 88, 190, 14, 181, 44, 186, 253
professor190 [17]

Answer:

A. index bits = 2, tag bits = 2, block offset bits = 1, it is a miss.

B. index bits = 2, tag bits = 1, block offset bits = 0, it is a hit

C. the miss rate is 0

Explanation:

a. number of blocks = 12

number of blocks per set = 3

number of set = number of blocks / number of blocks per set = 12/3 = 4

word size = 24

block size = 2

the block offset = log_{2} block size

   = log_{2} 2 = 1

the index bits = log_{2} number of set = log_{2} 4 = 2

the tag bits = (log_{2} word size) - offset - index = (log_{2} 24) -2 - 1 = 5 -2 - 1 = 2

b. word size = 8

block size = 1

the block offset = log_{2} block size

   = log_{2} 1 = 0

the index bits = log_{2} number of set = log_{2} 4 = 2

the tag bits = (log_{2} word size) - offset - index = (log_{2} 8) -2 - 1 = 3 - 0- 2= 1

7 0
3 years ago
Which of the following are cloud computing resources?
aleksandr82 [10.1K]
All of the above because it is accessible through computer access if you were to download them to any type of iCloud work
3 0
3 years ago
Read 2 more answers
What are the steps to configure user information in a document?
Svetach [21]

Answer: Step 1: Navigate to the document library where you would like to enable a Document Information Panel. Step 2: From Ribbon, click on settings to navigate to Library settings Page. Step 3: In the library Settings, you have to update the setting of content type. Enable management of content type if not already done.

6 0
3 years ago
Read 2 more answers
Other questions:
  • You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
    12·1 answer
  • Consider the following JavaScript program:
    8·1 answer
  • You have successfully compiled the file Hi.java, how do you run the corresponding program from the command line?
    7·1 answer
  • Your company has 1,000 users in a Microsoft Office 365 subscription. A Power BI administrator named Admin1 creates 20 dashboards
    14·1 answer
  • What is not soured of income
    6·1 answer
  • M f2.app.edmentum.com
    5·1 answer
  • Read the scenario and then answer the question using only the information provided.
    14·2 answers
  • Helpppppp meeeeeeeeeeeeeeeeee
    12·1 answer
  • You designed a program to find the midpoint of two points. Which step below corresponds to finding the average of the x-coordina
    15·1 answer
  • _____ are labels for data, while _____ tie values together into one entity.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!