111k views
3 votes
Determine the output of the following code segment:

int i;
int [] numbers = new int [10];
for (i = 0; i < numbers.length; i++)
{ numbers[i] = 2*(i - 5); numbers[i] = numbers[i] * numbers[i]; }
for (i = 0; i < numbers.length; i++)
{ System.out.println(numbers[i]);

1 Answer

5 votes

Answer:

The output to the given code as follows:

Output:

10

100

64

36

16

4

0

4

16

36

64

Step-by-step explanation:

In the given java code, an integer variable "i" and an array number is defined, which size is 10, in the next step two for loop is declared, that can be described as follows:

  • In the first loop, array use loop variable "i" use, which minus the value of 5 and multiplies by 2, and it will calculate the square of that number.
  • In the next step, a for loop is declared, that prints these array number variable square.
User RyuuGan
by
5.5k points