send edited code with all the all the variables in scope com
send edited code with all the all the variables in scope commented
package part1;
public class scope {
public static int foo(int num) {
int other_num = 2;
// ** variables in scope:
return num % other_num;
}
public static void main(String[] args) {
int odd = 0;
int x = 13;
for (int value = 0; value < x; value++) {
// ** variables in scope:
boolean local_odd = false;
int r = foo(value);
if (r == 1) {
// ** variables in scope:
local_odd = true;
} else {
int div = value/2;
System.out.println(div +\" divides \"+ value);
// ** variables in scope:
}
if (local_odd) {
odd++;
}
}
System.out.println(odd+\" odd numbers smaller than \"+x);
// ** variables in scope:
}
}
Part 1: Scope In the attached project, look at the file scope.java The file is marked in 5 places with a comment. Write in those comments the names of the variables that are in scope at that point in the code. public class scope [ public static int foo(int num) int other_num-2; / variables in scope: return num % other-num ; public static void main(String[] args) int odd0 intx 13; for Cint value-0 valueSolution
What is scope variable ?
Scope of a variable is the part of the program where the variable is accessible.
note : args are also consider as variable
here is code with comments:
public class scope {
public static int foo(int num) {
int other_num = 2;
// num , other_num
return num % other_num;
}
public static void main(String[] args) {
int odd = 0;
int x = 13;
for (int value = 0; value < x; value++) {
// value , odd , x , args
boolean local_odd = false;
int r = foo(value);
if (r == 1) {
// value , odd , x , local_odd, r , args
local_odd = true;
} else {
int div = value/2;
System.out.println(div +\" divides \"+ value);
// value , odd , x , local_odd, r , div , args
}
if (local_odd) {
odd++;
}
}
System.out.println(odd+\" odd numbers smaller than \"+x);
// odd , x , args
}
}

