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 VALENTINE
-Dominant- [34]

Answer:

i dont see the image

Explanation:

6 0
3 years ago
Read 2 more answers
A termination condition in a loop is analogous to________in a recursive method.
Varvara68 [4.7K]

Answer:

b) iteration.

Explanation:

There are various algorithms which are used in computer programming. Iteration is also a type of algorithm which is used to create loops. The instructions are inserted once and then these instructions are repeated to create a loop function.

8 0
3 years ago
Which tab is used to insert a hyperlink onto a slide
Roman55 [17]
The tab used to instead a Hyperlink into a slide is the Insert tab under the “Links” group.
5 0
3 years ago
Read 2 more answers
Write short notes on the following:<br>I. keyboard ii.Control unit iii.printer​
Andreas93 [3]

Answer:

- the Keyboard:

The keyboard is a handheld device used to input alphabet, numbers, symbols and characters to a monitor. It also houses the special manipulative and function keys.

- the Control Unit:

The control unit is a component of the CPU which directs the operation of the processor.

- the Printer:

The printer is an external hardware output device which takes electronic data stored on a device and creates a hard copy.

4 0
2 years ago
Why is it good to be a computer programmer?​
liubo4ka [24]

Answer:

It's your wish become other professions like doctor, engineer are also good. But in this profession you can make apps, websites and can do hacking. Which is are cool things to do. But every profession is best at it's profession.

Explanation:

If you like my answer than please mark me brainliest

5 0
2 years ago
Other questions:
  • Perhaps programs used for business purposes ought to conform to higher standards of quality than games. With respect to software
    7·1 answer
  • Write a class called SimpleSquare that has the following properties: - public int field called num - private int field called sq
    13·1 answer
  • What is the range of possible sizes for side<br> x?<br> 4.0<br> 2.7
    8·1 answer
  • You are planning to install Windows 10 on a computer in a dual-boot configuration. The computer already has Windows 8 installed.
    14·2 answers
  • A detective agency is looking to bust an arms sale. According to available intelligence, the sale is likely to happen in one of
    11·1 answer
  • Which of the following statements is true? Computer disks are volatile storage devices Volatile storage is lost when a computer
    12·2 answers
  • What is one advantage of using object-oriented programming?
    14·2 answers
  • What is an operating system?<br>​
    11·2 answers
  • A serial schedule:
    8·1 answer
  • Which website citation is correctly formatted according to MLA standards?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!