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
yulyashka [42]
2 years ago
8

Class Main {

Computers and Technology
1 answer:
tatyana61 [14]2 years ago
6 0

See below for the modified program in Java

<h3>How to modify the program?</h3>

The for loop statements in the program are:

  • for (int i = 0; i < arr.length; i++) { arr[i] = rd.nextInt(1000); }
  • for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }

To use the enhanced for loop, we make use of the for each statement.

This syntax of the enhanced for loop is:

for(int elem : elems)

Where elem is an integer variable and elems is an array or arrayList

So, we have the following modifications:

  • i = 0; for (int num : arr){ arr[i] = rd.nextInt(1000); i++;}
  • for (int num : arr) { System.out.println(num); }

Hence, the modified program in Java is:

class Main {

static int[] createRandomArray(int nrElements) {

Random rd = new Random();

int[] arr = new int[nrElements];

int i = 0;

for (int num : arr){

arr[i] = rd.nextInt(1000);

i++;

}

return arr;

}

static void printArray(int[] arr) {

for (int num : arr) {

System.out.println(num);

}

}

}

public static void main(String[] args) {

int[] arr = createRandomArray(5);

printArray(arr);

}

}

Read more about enhanced for loop at:

brainly.com/question/14555679

#SPJ1

You might be interested in
_______a file transfers a copy of the file from the storage media into your computer's memory?
Nana76 [90]
It's opening. I just took PF test (:
5 0
4 years ago
Read 2 more answers
Which statement is false? arrays may contain pointers. each entry in an array of strings is actually a pointer to the first char
konstantin123 [22]
<span>each entry in an array of strings is actually a pointer to the first character of a string

Each indice in an array of strings (which are actually each actually an array of char) is actually a pointer to the first (0th) char of a string.
</span>
4 0
3 years ago
Which element of presentation software can you use to add callouts and banners?
Harrizon [31]
<span><span>1.)From the Insert tab, select the Shapes command. A drop-down menu will appear.
</span><span>2.)Select the desired shape
3.)</span></span>Click and drag<span> the slide to create the shape. You may need to move or resize the shape so it points to the desired part of the image.
4.)</span><span>f you want your callout to contain text, start typing while the shape is selected.
5.)</span><span>From the </span>Format<span> tab, you can use the options in the </span>Shape Styles<span> group to customize the appearance of the shape. You can also adjust the font from the Home tab</span>
7 0
3 years ago
Read 2 more answers
What did Moore's Law explain?
kompoz [17]

Answer:

Moore's Law states that the number of transistors on a microchip doubles about every two years, though the cost of computers is halved. In 1965, Gordon E. Moore, the co-founder of Intel, made this observation that became Moore's Law.

Explanation:

4 0
3 years ago
Read 2 more answers
George wants to edit the font of the title in his presentation. Where can he find the option to edit it?
Bad White [126]

The answer could be B. Tool Bar

6 0
3 years ago
Read 2 more answers
Other questions:
  • The ____ shortcut keys remove character formatting. (points : 2) ctrl 0 (zero) ctrl i ctrl spacebar ctrl u
    8·2 answers
  • How do you scan a qr code on your iPhone
    5·2 answers
  • What is information technology?
    12·1 answer
  • True or False?If you live in a country that uses censorship,you may not be able to access certain websites.ONLY ANSWER IF UR 100
    9·2 answers
  • Create a trigger that prevents anychange(insert, update, or delete)to the grade attribute of the takesrelation that would change
    14·1 answer
  • Three broad categories of cryptographic algorithms are commonly used to create PRNGs: symmetric block ciphers, asymmetric cipher
    8·1 answer
  • Which SCSI standard allows for the technique known as “hot swapping”? Ultra SCSI Original SCSI Serial SCSI Fast-Wide SCSI
    5·1 answer
  • The visitor's age is stored in the variable age, the day of the week is stored in a variable day, and the price in dollars is st
    8·1 answer
  • When testing a game, why might you consider throttling the game’s “frames per second”?
    9·1 answer
  • in a particular factory, a team leader is an hourly paid production worker who leads a small team. in addition to hourly pay, te
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!