Lab Sheets 5 & 6: Java Control Statements

Arzath AreeffArzath Areeff
2 min read

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
      
0
Subscribe to my newsletter

Read articles from Arzath Areeff directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arzath Areeff
Arzath Areeff

I co-founded digizen.lk to promote online safety and critical thinking. Currently, I’m developing an AI app to fight misinformation. As Founder and CEO of ideaGeek.net, I help turn startup dreams into reality, and I share tech insights and travel stories on my YouTube channels, TechNomad and Rz Omar.