What is the exact screen output of the following Java program? Provide each step
ID: 3919647 • Letter: W
Question
What is the exact screen output of the following Java program?
Provide each step of your tracing data.
-----------------------------------------------------------
public class Problem11
{
public static void main(String [] args)
{
System.out.println( rangeProduct(3, 6) );
}
public static int rangeProduct(int a, int b)
{
int prod = 1;
int i = 0;
for(i = a; i <= b; i++)
prod = prod * i;
return(prod);
}
}
-----------------------------------------------------------
Tracing
line number main rangeProduct rangeProduct rangeProduct rangeProduct output a b i prodExplanation / Answer
Tracing
1 public class Problem11
{
2 public static void main(String [] args)
{
3 System.out.println( rangeProduct(3, 6) );
}
4 public static int rangeProduct(int a, int b)
{
5 int prod = 1;
6 int i = 0;
7 for(i = a; i <= b; i++)
8 prod = prod * i;
9 return(prod);
}
}
line 3 functiion call rangeProduct(3,6)
line 4 a = 3 ,b = 6
line 5 a = 3 ,b = 6, prod =1
line 6 a = 3 ,b = 6, prod =1, i =0
line 7 a = 3 ,b = 6, prod =1, i =3
line 8 a = 3 ,b = 6, , i =3, prod =prod*i= 3
line 7 a = 3 ,b = 6, prod =3, i =4
line 8 a = 3 ,b = 6, i =4 , prod =prod*i= 3*4= 12
line 7 a = 3 ,b = 6, i =5 , prod =12
line 8 a = 3 ,b = 6, i =5 , prod =prod*i= 12*5= 60
line 7 a = 3 ,b = 6, i =6 , prod =60
line 8 a = 3 ,b = 6, i =6 , prod =prod*i= 60*6 = 360
line 7 a = 3 ,b = 6, i =7 , prod =360
loop breaks
line 9 prod = 360 returned
line 3 output 360 printed...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.