For each of the variables in the following program, indicate the scope. Then determine what the program

Question:

For each of the variables in the following program, indicate the scope. Then determine what the program prints, without actually running the program.

1 public class Sample
2 {
3 public static void main(String[] args)
4 {
5 int i = 10;
6 int b = g(i);
7 System.out.println(b + i);
8 }
9
10 public static int f(int i)
11 {
12 int n = 0;
13 while (n * n <= i) { n++; }
14 return n - 1;
15 }
16
17 public static int g(int a)
18 {
19 int b = 0;
20 for (int n = 0; n < a; n++)
21 {
22 int i = f(n);
23 b = b + i;
24 }
25 return b;
26 }
27 }

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java Concepts Late Objects

ISBN: 9781119186717

3rd Edition

Authors: Cay S. Horstmann

Question Posted: