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.
int sum = 0; for (int i = 1; i <= n; i++) sum += i; System.out.println(sum);
No citable source has been recorded for this record. Treat it as practice material, not as fact.
The same result is given by the formula n(n + 1)/2, which needs no loop at all.
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
Distinguish between the break and the continue statements.
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