ITRevise.in

Chapter library

Operators and Control Flow · Class XII · Part B

Open an answer to check your recall, or turn this topic into an MCQ quiz.

Fundamentals of Java Programming

Operators and Control Flow

Practice this chapter
Testing an if-else decision. Read the score. Is score at least 40?. Yes: print Pass. No: print Try again.
Test boundary values such as 39 and 40.
1 Explain “Remainder operator” with an example.

Remainder operator returns the remainder after division.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. Logical AND requires both Boolean conditions to be true. If-else chooses one of two branches. Switch chooses a branch from matching cases.

Example. The Java expression 17 % 5 gives 2. Integer division makes three full groups of five, which account for 15. The two left over are the remainder. This is useful in a test such as number % 2 == 0 for checking an even integer.

The important point is what “Remainder operator” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

168 words

2 Explain “Logical AND” with an example.

Logical AND requires both Boolean conditions to be true.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. If-else chooses one of two branches. Switch chooses a branch from matching cases. While loop checks its condition before each iteration.

Example. A marks program prints “Pass” if a score is at least 40. In a test with 39, the condition is false. In a test with 40, it is true. Testing the value right at the boundary checks whether the comparison includes 40 as the rule requires.

The important point is what “Logical AND” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

173 words

3 Explain “If-else” with an example.

If-else chooses one of two branches.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. Switch chooses a branch from matching cases. While loop checks its condition before each iteration. Do-while loop checks its condition after the loop body.

Example. A marks program prints “Pass” if a score is at least 40. In a test with 39, the condition is false. In a test with 40, it is true. Testing the value right at the boundary checks whether the comparison includes 40 as the rule requires.

The important point is what “If-else” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

172 words

4 Explain “Switch” with an example.

Switch chooses a branch from matching cases.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. While loop checks its condition before each iteration. Do-while loop checks its condition after the loop body. For loop groups setting the starting value, condition and update in its header.

Example. Several computers and a shared printer connect to a switch in the school lab. It directs local network traffic to the appropriate connection when it knows where the destination device is. A router serves a different role when data needs to cross between networks.

The important point is what “Switch” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

177 words

5 Explain “While loop” with an example.

While loop checks its condition before each iteration.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. Do-while loop checks its condition after the loop body. For loop groups setting the starting value, condition and update in its header. Remainder operator returns the remainder after division.

Example. Suppose a program starts at 1 and prints the number while it is at most 3, increasing it by 1 each time. It prints 1, 2 and 3. When the value becomes 4 the test is false and the loop stops.

The important point is what “While loop” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

175 words

6 Explain “Do-while loop” with an example.

Do-while loop checks its condition after the loop body.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. For loop groups setting the starting value, condition and update in its header. Remainder operator returns the remainder after division. Logical AND requires both Boolean conditions to be true.

Example. If a menu should appear at least once before a student decides whether to continue, a do-while loop can show the menu first. It checks the condition after that first action. A while loop can skip its body when its condition is false at the beginning.

The important point is what “Do-while loop” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

181 words

7 Explain “For loop” with an example.

For loop groups setting the starting value, condition and update in its header.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. Remainder operator returns the remainder after division. Logical AND requires both Boolean conditions to be true. If-else chooses one of two branches.

Example. A marks program prints “Pass” if a score is at least 40. In a test with 39, the condition is false. In a test with 40, it is true. Testing the value right at the boundary checks whether the comparison includes 40 as the rule requires.

The important point is what “For loop” does in a specific situation. To see the difference between this idea and the others in this chapter, compare what each one affects and which result would show that it had been used correctly. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

178 words

8 Distinguish between Remainder operator and Logical AND.

Remainder operator returns the remainder after division. Logical AND requires both Boolean conditions to be true.

Trace Java code in the order it executes. Keep track of the type and value of each variable, which condition is evaluated and how the result is returned or shown. If-else chooses one of two branches. Switch chooses a branch from matching cases. While loop checks its condition before each iteration.

Example. A marks program prints “Pass” if a score is at least 40. In a test with 39, the condition is false. In a test with 40, it is true. Testing the value right at the boundary checks whether the comparison includes 40 as the rule requires.

Compare the two ideas using the same situation. Describe which part of the situation each idea explains and how the result would differ if you used the other one. This gives the distinction a clearer basis than listing two definitions in isolation. Use one concrete detail, such as a number, file name, message or action, to show exactly what you mean and how someone could check it.

181 words

Reference book: 802-Information Technology Class- XII_PART_B.pdf