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
Advantages of e commerce
Sloan [31]

Answer:

A Larger Market

Customer Insights Through Tracking And Analytics

Fast Response To Consumer Trends And Market Demand

Lower Cost

More Opportunities To "Sell"

Personalized Messaging

Hope this helps!

4 0
4 years ago
A device that filters data traffic at a network boundary​
Semmy [17]

Answer:

Bridges

Explanation:

A bridge is a transition effects that separates network traffic at the network's edge. By splitting a local area network into two parts, bridges minimise the number of bandwidth.

6 0
3 years ago
What happens when you create a variable in a video game program?​
gulaghasi [49]

Answer:

A lot can happen, depending on the use of the variable

Explanation:

Lets create a position variable, a common variable in games.

Vector3 position = new Vector3(0, 0, 0);

The above variable initialization creates a new Vector3 object. The Vector3 class contains 3 properties, X, Y, and Z. When you assign the variable 'position' the new Vector3 object, the variable 'position' contains an instance of Vector3 where

X = 0,

Y = 0,

and Z = 0.

The variable 'position' can be used to set the position of a player, or an object.

We can reuse this variable when you want the object or player to move.

position.X = 29

position.Y = -14

position.Z = 47

now the object/player's position is (29, -14, 47).

Variables can be used for basically everything you need in programming, from storing a position, to storing the result of a complex math equation.

7 0
3 years ago
Which of the following statements holds true for the term "html"? It refers to a system that connects end users to the Internet.
Oksana_A [137]

Answer:

Your answer is B. It refers to the language used to create and format Web pages.

Explanation:

HTML stands for "Hyper Text Markup Language", which is a specification used on any webpage, ever. It was created by Sir Tim Berners-Lee in late 1991 and was officially released in 1995. This language is actually what is sent to your browser, which then interprets it and allows you to see the pretty pictures of Brainly.com! As of right now, HTML is at it's 5th revision, also known as HTML5, which is another term you'll see around.

Thanks, let me know if this helped!

3 0
3 years ago
Read 2 more answers
The computer virus is simply a.......... a. diseases b.set of computer instrustruction or code c. types of bacteria​
Svetllana [295]

Answer: b

The computer virus is simply a ___

b. Set of computer instructions or code

4 0
3 years ago
Other questions:
  • Not providing guarding or fall protection for workers on a 25-foot scaffold. The resulting fall would most likely end in death,
    6·1 answer
  • Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volu
    11·2 answers
  • Josh's boss asked him to write a letter to their customers explaining some upcoming price increases. But Josh was in a hurry to
    8·2 answers
  • An ip address in the address range 169.254.x.y, used by a computer when it cannot successfully lease an ip address from a dhcp s
    6·1 answer
  • A website is a collection of​
    12·2 answers
  • Describe the importance of human interaction in a computing system.
    14·2 answers
  • The best way to safeguard your document is to save it
    11·1 answer
  • when working with smart which tab would provide the ability to change the shape or size of the smart art shapes
    15·2 answers
  • 6. You and your friends take an awesome selfie, and you add your name and addresses to the picture. It is a good idea to share t
    11·1 answer
  • Name any three areas of of application of excel.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!