Answer to Question #273956 in Java | JSP | JSF for harryy

Question #273956

Today, we shall compute for the squares of all the numbers.


There's already a predefined array/list containing 100 integer values. Loop through each values, compute their squares, and display them.


public class Main {


    public static void main(String[] args) {

        int[] array = {

            2, 3, 5, 100, 7, 3, 5, 3, 1, 4,

            76, 77, 78, 79, 80, 54, 68, 61, 34, 33,

            44, 49, 100, 5, 2, 87, 34, 33, 2, 1,

            4, 5, 8, 2, 1, 8, 5, 3, 2, 1,

            88, 22, 23, 33, 48, 44, 46, 48, 50, 52,

            45, 47, 49, 51, 53, 1, 1, 1, 1, 1,

            1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

            20, 19, 18, 17, 16, 15, 14, 13, 12, 11,

            11, 22, 33, 44, 55, 66, 77, 88, 99, 100,

            1000, 2001, 3000, 4001, 5000, 6001, 7000, 8001, 9000, 10001

        };

        for (int i = 0; )

    }

}


Output

Multiple lines containing an integer.

4
9
25
10000
49
9
25
9
1
16
.
.
.




1
Expert's answer
2021-12-01T18:38:52-0500
public class Main {

    public static void main(String[] args) {
        int[] array = {
                2, 3, 5, 100, 7, 3, 5, 3, 1, 4,
                76, 77, 78, 79, 80, 54, 68, 61, 34, 33,
                44, 49, 100, 5, 2, 87, 34, 33, 2, 1,
                4, 5, 8, 2, 1, 8, 5, 3, 2, 1,
                88, 22, 23, 33, 48, 44, 46, 48, 50, 52,
                45, 47, 49, 51, 53, 1, 1, 1, 1, 1,
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                20, 19, 18, 17, 16, 15, 14, 13, 12, 11,
                11, 22, 33, 44, 55, 66, 77, 88, 99, 100,
                1000, 2001, 3000, 4001, 5000, 6001, 7000, 8001, 9000, 10001
        };
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i] + "^2 = " + array[i] * array[i]);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS