Write a Java program segment to check whether a given integer n is prime.
Iterative Constructs
Original Khojo Papers practice question — not from a past board paper.
break terminates the loop or switch immediately and passes control to the statement after it. continue skips the rest of the current iteration and moves to the next iteration of the loop, so the loop itself is not terminated.
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Both affect only the innermost enclosing loop unless a label is used.
From the same topic and chapter, at a similar level.
Write a Java program segment to check whether a given integer n is prime.
Iterative Constructs
How many times does the body of this loop execute: for (int i = 10; i > 0; i -= 3) { … }
Iterative Constructs
State three differences between a while loop and a do-while loop.
Iterative Constructs
Write a Java program segment to find the sum of the first n natural numbers using a for loop.
Iterative Constructs
Explain the ternary operator in Java and rewrite "if (a > b) max = a; else max = b;" using it.
Operators and Expressions in Java
What is the output of: String s = "Examination"; System.out.println(s.length() + " " + s.substring(0, 4) + " " + s.toUpperCase().charAt(2));
String Handling