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 company has recently learned of a person trying to obtain personal information of employees illegally. According to which act
Juli2301 [7.4K]

Answer

Digital Millennium Act

Explanation

The Digital Millennium Copyright Act  is a United States copyright law that implements two  treaties of the World Intellectual Property Organization . The aim of this ACT is to protect the rights of both copyright owners and consumers. The law complies with the World Intellectual Property Organization  Copyright. The law has two basic functions. First, it protects copyright owners by providing them with a mechanism to enforce their rights without having to directly sue the infringer

7 0
2 years ago
Read 2 more answers
Write a Python program that prints all the numbers from 0 to 6 except 3
svetlana [45]

Explanation is in the file

tinyurl.com/wpazsebu

8 0
2 years ago
Can someone write me a design brief about a stadium​
Delicious77 [7]

Btw..which dtadium do u want cricket or football!?

3 0
2 years ago
Read 2 more answers
The type of software used widely in businesses to complete specific tasks is _____. application software programming language sy
max2010maxim [7]
It is eather pythone or html
8 0
3 years ago
Read 2 more answers
Match the parts of the software applications with what they do.
Lady_Fox [76]

1-h

2-f

3-e

4-g

5-d

6-c

7-b

8-a

4 0
2 years ago
Other questions:
  • What will be the value of ans after the following code has been executed?
    10·2 answers
  • 2. Use inheritance to create a hierarchy of Exception classes -- EndOfSentenceException, PunctuationException, and CommaExceptio
    6·1 answer
  • Anyone wanna play among us UwU code is TAEQPQ
    15·2 answers
  • ____________________ is the primary code humans use to communicate. (Points : 1
    9·1 answer
  • Blair is the director of information systems at a marketing firm. She creates a set of guidelines that dictate everything an emp
    12·1 answer
  • New trends, tools, and languages emerge in the field of web technology every day. Discuss the advantages of these trends, tools,
    15·1 answer
  • 8.2 Code Practice Edhesive
    6·1 answer
  • How can i fix a all white phone screen
    11·2 answers
  • Write a program that repeatedly reads in integers until a negative integer is read. The program keeps track of the largest integ
    9·1 answer
  • What is output?<br> x = 2<br> y = 3<br> print (x * y + 2)<br> 4<br> 2<br> 8<br> 10
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!