For this discussion, we are going to be working with operators. Below is the code for the Operators class, which contains a main() method and a divisible() method. Study the code below, paying special attention to the four if statements. First, explain using complete sentences how each if statement evaluates (true or false), as well as what takes place in each if statement's test (comparisons, function calls, increments/decrements, etc.). Then, provide what the program will output. public class Operators { public static void main(String[] args) { int a = 5, b = 10, c = 11; System.out.println("This program works with operators."); if (a < 10 ^ b == 10) System.out.println("Java "); if (divisible(b, a) | divisible(c, a)) System.out.println("Programming "); if (a + b - (++c) == c - (b--) + 1) System.out.println("CITC "); if (divisible(c, a) && divisible(++b, a)) System.out.println("OCA"); } public static boolean divisible(int a, int b) { if (a % b == 0) { System.out.println(a + " is evenly divisible by " + b); return true; } else { System.out.println(a + " is not evenly divisible by " + b); return false; } } }
For this discussion, we are going to be working with operators. Below is the code for the Operators class, which contains a main() method and a divisible() method.
Study the code below, paying special attention to the four if statements. First, explain using complete sentences how each if statement evaluates (true or false), as well as what takes place in each if statement's test (comparisons, function calls, increments/decrements, etc.). Then, provide what the program will output.
public class Operators {
public static void main(String[] args) {
int a = 5, b = 10, c = 11;
System.out.println("This program works with operators.");
if (a < 10 ^ b == 10)
System.out.println("Java ");
if (divisible(b, a) | divisible(c, a))
System.out.println("
if (a + b - (++c) == c - (b--) + 1)
System.out.println("CITC ");
if (divisible(c, a) && divisible(++b, a))
System.out.println("OCA");
}
public static boolean divisible(int a, int b) {
if (a % b == 0) {
System.out.println(a + " is evenly divisible by " + b);
return true;
}
else {
System.out.println(a + " is not evenly divisible by " + b);
return false;
}
}
}
This is related to Java Program and its operator.
Answer is in step 2 with explanation
Step by step
Solved in 2 steps