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
 
 public class scope {
 
 public static int foo(int num) {
 int other_num = 2;
 // ** variables in scope is Method Level Scope(Variables declared inside a method have method level scope and can’t be accessed outside the method.)   
 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 is Block Scope(A variable declared inside pair of brackets “{” and “}” in a method has scope within the brackets only.)
 boolean local_odd = false;
 int r = foo(value);
 if (r == 1) {
 // ** variables in scope is Block Scope(A variable declared inside pair of brackets “{” and “}” in a method has scope within the brackets only.)
 local_odd = true;
 } else {
 int div = value/2;
 System.out.println(div +\" divides \"+ value);
 // ** variables in scope is Block Scope(A variable declared inside pair of brackets “{” and “}” in a method has scope within the brackets only.)
 }
 if (local_odd) {
 odd++;
 }
 }
 System.out.println(odd+\" odd numbers smaller than \"+x);
 // ** variables in scope is Method Level Scope(Variables declared inside a method have method level scope and can’t be accessed outside the method.)
 }
 }


