asked 91.9k views
11 votes
What is the output of the following code? Assume the Rectangle class exists and all the methods called below exist and work as expected.

ArrayList blah = new ArrayList ();
blah.add( new Rectangle(3,5) );
blah.add( new Rectangle(2,15) );
blah.add( new Rectangle(5,5) );
double x=0;

System.out.println(blah.size());
for(Rectangle s: blah) x+=s.area();
System.out.println(x);

1 Answer

7 votes

Answer:

3

70.0

Step-by-step explanation:

There will be 3 elements (Rectangle instances) in the list.

The sum of the areas x will contain 3*5 + 2*15 + 5*5 = 70 and will be printed as a double.

answered
User Hernando Casas
by
7.4k points

Related questions

asked Sep 7, 2024 80.9k views
Kohske asked Sep 7, 2024
by Kohske
8.1k points
1 answer
1 vote
80.9k views
asked Nov 18, 2024 234k views
JP Blanco asked Nov 18, 2024
by JP Blanco
8.2k points
1 answer
3 votes
234k views
1 answer
4 votes
123k views