Ask Question
5 July, 13:11

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

+3
Answers (1)
  1. 5 July, 16:00
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers