Ask Question
8 January, 14:12

What is output by the following code?

int a [] = {64, 66, 67, 37, 73, 70, 95, 52, 81, 82};

for (int i = 0; i < a. length; i++) {

a[i] = a[i] / 10;

}

for (int i = 0; i < a. length; i++) {

System. out. print (a[i] + " ");

}

1. 7 7 7 4 8 8 10 6 9 9

2. 6 6 6 3 7 7 9 5 8 8

3. 5 7 8 8 4 1 6 3 2 3

4. 2 4 5 2 2 8 6 8 1 2

5. 4 6 7 7 3 0 5 2 1 2

+1
Answers (1)
  1. 8 January, 16:29
    0
    When numbers are divided, the integer portion is kept and the remainder is disregarded (meaning 10/9 would return 1). Following this format, we get the answer of 6 6 6 3 7 7 9 5 8 8.

    I also see that this program can be optimized because you use the same for loop twice, and both of them manipulate list elements in some way. A more optimized program would be:

    int a [] = {64, 66, 67, 37, 73, 70, 95, 52, 81, 82};

    for (int i = 0; i < a. length; i++) {

    a[i] = a[i] / 10;

    System. out. print (a[i] + " ");

    }

    Or maybe you don't need to store the list values for later on. You could do:

    for (int i = 0; i < a. length; i++) {

    System. out. print (a[i] / 10 + " ");

    }

    In any situation, your answer is choice 2.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is output by the following code? int a [] = {64, 66, 67, 37, 73, 70, 95, 52, 81, 82}; for (int i = 0; i < a. length; i++) { a[i] = ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers