Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

22nd May 2021, 5:15 PM
Igaman Igaman
Igaman Igaman - avatar
4 Answers
+ 2
Show your attemps so we can help you out
22nd May 2021, 5:17 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
May I know when you are printing the result?
22nd May 2021, 6:00 PM
Atul [Inactive]
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(); } } }
22nd May 2021, 5:20 PM
Igaman Igaman
Igaman Igaman - avatar
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 .
22nd May 2021, 6:53 PM
Jayakrishna 🇮🇳