Sample Set 1 - Class 10 Computer Answers
1. What is the use of a flowchart in programming?
Flowcharts help in visually representing the logic of a program. They make it easier to understand,
analyze, and debug the flow of control in a program.
2. Write the syntax and example of 'if...else' statement in Java.
Syntax:
if (condition) {
// statements
} else {
// statements
Example:
if (a > b) {
[Link]("A is greater");
} else {
[Link]("B is greater");
3. What is the use of Scanner class? Give example.
Scanner class is used to take input from the user in Java. Example:
Scanner sc = new Scanner([Link]);
int num = [Link]();
4. What is the difference between entry-controlled and exit-controlled loop?
Entry-controlled loops check the condition before executing the loop (e.g., 'for', 'while').
Exit-controlled loops check the condition after executing the loop once (e.g., 'do-while').
5. Write a program in Java to check whether the number is even or odd.
import [Link].*;
class EvenOdd {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int n;
[Link]("Enter a number: ");
n = [Link]();
if (n % 2 == 0)
[Link]("Even number");
else
[Link]("Odd number");