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
Vladimir [108]
3 years ago
7

What does the following loop do?int[] a = {6, 1, 9, 5, 12, 3};int len = a.length;int x = 0;for (int i = 1; i < len; i++)if (a

[i] > a[x]) x = i;System.out.println(x);1. Finds the position of the largest value in a.2. Sums the elements in a.3. Finds the position of the smallest value in a.4. Counts the elements in a.
Computers and Technology
1 answer:
Marat540 [252]3 years ago
8 0

Answer:

Option 1: Finds the position of the largest value in a

Explanation:

Given the codes as follows:

  1.        int[] a = {6, 1, 9, 5, 12, 3};
  2.        int len = a.length;
  3.        int x = 0;
  4.        for (int i = 1; i < len; i++)
  5.        {
  6.            if (a[i] > a[x])
  7.                x = i;
  8.        }
  9.        System.out.println(x);

The code is intended to find a largest value in the array, a. The logic is as follows:

  • Define a variable to hold an index where largest value positioned. At the first beginning, just presume the largest value is held at index zero, x = 0. (Line 3)
  • Next, compare the value location in next index. If the value in the next index is larger, update the index-x to the next index value (Line 4 - 8). Please note the for-loop traverse the array starting from index 1. This is to enable the index-1 value can be compared with index-0 and then followed with index-2, index-3 etc.
  • After completion of the for-loop, the final x value will be the index where the largest value is positioned.
  • Print the position of the largest value (Line 10)

You might be interested in
You must. place a child in a federally approved child restraint device. if the child is
abruzzese [7]
You must place a child in a federally approved child restraint device if the child is three years and under. 
5 0
3 years ago
Read 2 more answers
Who was the father of computer?????​
adell [148]

Answer:

Charles Babbage

Explanation:

4 0
3 years ago
Read 2 more answers
What is an example of an assumption and dependency that an automated stocking application project would include in an SRS?
Natasha2012 [34]

Explanation:

software must be used by well trained staff.

6 0
2 years ago
In a PivotTable, how can a field of data be hidden from the viewer but still be active in calculations made by Excel’s formulas?
Nuetrik [128]
C. The user can select a cell in that field and click “collapse entire field” in the options tab. Is probably not right!
5 0
3 years ago
Pls help is very urgent and I will mark u as brainliest plsssss​
elena-s [515]

Answer:

this is the method of processing wood

5 0
3 years ago
Read 2 more answers
Other questions:
  • The support group at Universal Containers wants agents to capture different information for product support and inquiry cases. I
    14·1 answer
  • You use a(n) ____ variation when a use case is less specific than others, and you want to be able to substitute the more specifi
    8·1 answer
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • Someone who participates online for social reasons usually has a:
    9·1 answer
  • How would you classify an employee who is punctual, has respect for oneself and others, and takes initiative?
    13·2 answers
  • You are given the task of reading in n numbers and then printing them out in sorted order. Suppose you have access to a balanced
    12·1 answer
  • Which type of error occurred in the following lines of code?
    13·1 answer
  • Which area of government regulations do the Fair Credit and Reporting Act
    8·2 answers
  • FILL IN THE BLANK.
    10·1 answer
  • When trying to upload assignment on canvas wont let me click choose file.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!