0
Java
Your company is creating a curriculum for a geometry course. This program takes the number of squares as input, creates an array, and then the sides of the squares as its elements. You need to supplement the program that will take a list of the sides of the squares and display the areas of these squares for the user. Sample input 2 3 4 Result 9 16
4 odpowiedzi
+ 2
Show your attemps so we can help you out
+ 1
May I know when you are printing the result?
0
please explain, I don't understand arrays well with loops
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int[] sides = new int[length];
for (int i = 0; i < length; i++) {
sides[i] = scanner.nextInt();
}
}
}
0
Input sample
2
3
4
int[] sides = new int[length]; //this will initialize array of size 'length' for sample 2.
Next
for (int i = 0; i < length; i++)
sides[i] = scanner.nextInt(); //this will take next 'length'(2) of inputs into i'th location in sides array..
(3 into 0th index, 4 into 1st index location)
Similar way with another loop print array values squires sizes[I]*sizes[I] as output .