What is Pseudocode?
Pseudocode is a human-readable way to describe the steps of an algorithm without worrying about syntax of a specific programming language.
It is written in plain English (or any natural language) but structured like code.
Why use pseudocode?
- Easy to understand for both technical and non-technical people.
- Helps in planning before coding.
- Reduces errors in implementation.
Rules for Writing Good Pseudocode
- Use plain, simple language – avoid unnecessary jargon.
- Write one action per line – keep it clean.
- Use indentation – to represent loops or conditional blocks.
- Use standard keywords like:
START,ENDIF,ELSE,ENDIFFOR,WHILE,REPEATREAD,PRINT,RETURN
- Keep it language-independent – no need for Java, Python, or C++ syntax.
- Number your steps if sequence matters.
Pseudocode and Java Implementations
Example 1 – Find if a number is even or odd
Problem:
Write an algorithm to read a number and determine whether it is even or odd.
Pseudocode:
1. START
2. READ number N
3. IF N mod 2 = 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
4. END
import java.util.Scanner;
public class EvenOddCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int N = sc.nextInt();
if (N % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
Example 2 – Sum of Two Numbers
Problem: Read two numbers and print their sum.
Pseudocode:
START
READ A, B
SUM ← A + B
PRINT SUM
END
import java.util.Scanner;
public class SumOfTwoNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int A = sc.nextInt();
System.out.print("Enter second number: ");
int B = sc.nextInt();
int SUM = A + B;
System.out.println("Sum = " + SUM);
}
}
Example 3 – IF Statement
Problem: Check if a number is positive.
Pseudocode:
START
READ num
IF num > 0 THEN
PRINT "Positive Number"
ENDIF
END
import java.util.Scanner;
public class PositiveCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num > 0) {
System.out.println("Positive Number");
}
}
}
Example 4 – IF...ELSE Statement
Problem: Check if a person is eligible to vote.
Pseudocode:
START
READ age
IF age >= 18 THEN
PRINT "Eligible to Vote"
ELSE
PRINT "Not Eligible to Vote"
ENDIF
END
import java.util.Scanner;
public class VotingEligibility {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();
if (age >= 18) {
System.out.println("Eligible to Vote");
} else {
System.out.println("Not Eligible to Vote");
}
}
}
Example 5 – Nested IF
Problem: Find the largest among three numbers.
Pseudocode:
START
READ A, B, C
IF A > B THEN
IF A > C THEN
PRINT "A is the largest"
ELSE
PRINT "C is the largest"
ENDIF
ELSE
IF B > C THEN
PRINT "B is the largest"
ELSE
PRINT "C is the largest"
ENDIF
ENDIF
END
import java.util.Scanner;
public class LargestNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter three numbers: ");
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
if (A > B) {
if (A > C) {
System.out.println("A is the largest");
} else {
System.out.println("C is the largest");
}
} else {
if (B > C) {
System.out.println("B is the largest");
} else {
System.out.println("C is the largest");
}
}
}
}
Example 6 – Nested FOR Loop
Problem: Print a multiplication table from 1 to 5.
Pseudocode:
START
FOR i ← 1 TO 5 DO
FOR j ← 1 TO 10 DO
PRINT i × j
ENDFOR
ENDFOR
END
public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 10; j++) {
System.out.println(i + " x " + j + " = " + (i * j));
}
System.out.println();
}
}
}
Example 7 – WHILE Loop
Problem: Print numbers from 1 to N.
Pseudocode:
START
READ N
i ← 1
WHILE i <= N DO
PRINT i
i ← i + 1
ENDWHILE
END
import java.util.Scanner;
public class PrintNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter N: ");
int N = sc.nextInt();
int i = 1;
while (i <= N) {
System.out.println(i);
i++;
}
}
}
Example 8 – REPEAT UNTIL Loop (Simulated with do-while in Java)
Problem: Keep reading numbers until the user enters 0.
Pseudocode:
START
REPEAT
READ num
PRINT num
UNTIL num = 0
END
import java.util.Scanner;
public class RepeatUntilExample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
do {
System.out.print("Enter a number (0 to stop): ");
num = sc.nextInt();
System.out.println("You entered: " + num);
} while (num != 0);
}
}
Example 9 – IF with AND/OR Condition
Problem: Check if a number is between 10 and 50.
Pseudocode:
START
READ num
IF num >= 10 AND num <= 50 THEN
PRINT "Number is in range"
ELSE
PRINT "Number is out of range"
ENDIF
END
import java.util.Scanner;
public class NumberRangeCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num >= 10 && num <= 50) {
System.out.println("Number is in range");
} else {
System.out.println("Number is out of range");
}
}
}
Example 10 – Combining IF and FOR
Problem: Print only even numbers between 1 and N.
Pseudocode:
START
READ N
FOR i ← 1 TO N DO
IF i MOD 2 = 0 THEN
PRINT i
ENDIF
ENDFOR
END
import java.util.Scanner;
public class EvenNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter N: ");
int N = sc.nextInt();
for (int i = 1; i <= N; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
}
}
▶ Next: Why Learn DSA?