Question about code result
Please look at Enhanced For Loops section in Java. The problem is called Geometry Code. This code below works, but I'm having problems making sense of the first answer. The sample input is 2 3 4, meaning 2 squares with the sides that are 3 and 4 so I'm simply supposed to find the area 3Ć3=9 and 4x4=16 The problem is that when these numbers are entered 3 2 3 the output is 4 9 25. I cannot make sense of these results. Here's the code but as far as I know there's nothing wrong with the code. 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(); } //your code goes here int area = 0; for (int x = 0; x < length; x++){ area = sides[x] * sides[x]; System.out.println(area); } } }