Skip to main content

Command Palette

Search for a command to run...

Lab Sheets 5 & 6: Java Control Statements

Published
2 min read
Lab Sheets 5 & 6: Java Control Statements
A
I co-founded🫆digizen (fighting internet chaos 🧠), building an AI app to tackle misinformation, and running ideaGeek to turn “I have an idea” into real startups. I also share tech + travel on YouTube (TechNomad & Rz Omar). I touch grass too 🌱… but mostly to debug life 💻

Part 1: Sequential Flow (Sequence Logic)

  1. Write a Java program that takes two numbers as input and prints their sum, difference, product, and quotient in sequence.

Part 2: Conditional Statements (Selection Logic)

  1. If-Else Statement:

    • Write a program that checks if a given number is even or odd.

    • Write a program that determines the largest among three numbers.

  2. Switch Statement:

    • Write a program that takes a day number (1-7) and prints the corresponding day name (e.g., 1 → "Monday").

Part 3: Loops (Iteration Logic)

  1. For Loop:

    • Write a program to print the first 10 natural numbers.

    • Write a program to calculate the factorial of a number.

  2. While Loop:

    • Write a program to print all even numbers between 1 and 20.

    • Write a program to find the sum of digits of a given number.

  3. Do-While Loop:

    • Write a program that keeps asking the user to enter a number until they enter a negative number.

    • Write a program to print the multiplication table of a number using do-while.


Challenge Problems

  1. Nested Control Structures:

    • Write a program to check if a number is prime or not.

    • Write a program to print the Fibonacci series up to 'n' terms.

  2. Pattern Printing:

    • Use nested loops to print the following patterns:

        *
        **
        ***
        ****
        *****
      
        1
        12
        123
        1234
        12345
      

More from this blog

T

TechNomad

46 posts

TechNomad is mostly coding exercises, not long boring explanations 😌. I share what I teach and learn through hands-on problems—mainly for my students, but anyone can jump in. If you learn by doing (and breaking things), you’ll fit right in. Less theory, more “try this and see what happens.”