Java Programs›Control Flow

🔄Java Control Flow Programs

Control flow is the first thing to get comfortable with in Java: making decisions with if-else and switch, and repeating work with for and while loops. These short programs are ideal for beginners and for quick revision before an interview.68 programs · each with full code, output and a step-by-step explanation

Most Asked in Interviews

🔍
Beginner
01beginner
Check Character Is Alphabet
Conditional Statements

Determines whether a given character is a letter of the alphabet.

View Program →
02beginner
Check Character Is Digit
Conditional Statements

Determines whether a given character is a numeric digit.

View Program →
03beginner
Check Character Is Special Character
Conditional Statements

Determines whether a given character is neither a letter nor a digit.

View Program →
04beginner
Check Character Is Vowel or Consonant
Conditional Statements

Determines whether a given letter is a vowel or a consonant.

View Program →
05beginner
Check Even or Odd
Conditional Statements

Determines whether a given number is even or odd.

View Program →
06beginner
Check Number Divisible by 3 or 5
Conditional Statements

Determines whether a number is divisible by either 3 or 5.

View Program →
07beginner
Check Number Divisible by 5 and 11
Conditional Statements

Determines whether a number is divisible by both 5 and 11 at once.

View Program →
08beginner
Check Number Duck
Loops

Determines whether a number contains a zero digit anywhere in it.

View Program →
09beginner
Check Number Harshad
Loops

Determines whether a number is exactly divisible by the sum of its own digits.

View Program →
10beginner
Check Number Neon
Loops

Determines whether the sum of the digits of a number's square equals the number itself.

View Program →
11beginner
Check Number Within Range
Conditional Statements

Determines whether a number falls within a given lower and upper bound.

View Program →
12beginner
Check Positive or Negative
Conditional Statements

Determines whether a number is positive, negative, or zero.

View Program →
13beginner
Check Uppercase or Lowercase
Conditional Statements

Determines whether a given letter is uppercase or lowercase.

View Program →
14beginner
Check Valid Triangle
Conditional Statements

Determines whether three given side lengths can form a valid triangle.

View Program →
15beginner
Check Voting Eligibility
Conditional Statements

Determines whether a person's age meets the minimum voting age.

View Program →
16beginner
Check Vowel Using Switch
Switch Statement

Determines whether a character is a vowel using a switch statement with stacked case labels.

View Program →
17beginner
Check Zero or Non-Zero
Conditional Statements

Determines whether a number is zero or non-zero.

View Program →
18beginner
Count Digits in a Number
Loops

Counts how many digits a given number has.

View Program →
19beginner
Count Numbers in a Range
Loops

Counts how many whole numbers fall within a given inclusive range, using a loop.

View Program →
20beginner
Find First Digit
Loops

Finds the leftmost digit of a given number.

View Program →
21beginner
Find Largest of Two Numbers
Conditional Statements

Determines which of two given numbers is the larger.

View Program →
22beginner
Find Last Digit
Loops

Extracts the last digit of a number using the modulo operator.

View Program →
23beginner
Find Smallest of Two Numbers
Conditional Statements

Determines which of two given numbers is the smaller.

View Program →
24beginner
FizzBuzz
Loops

Classic loop-and-conditional warm-up exercise.

View Program →
25beginner
Grade Description Using Switch
Switch Statement

Looks up a short description for an already-known letter grade.

View Program →
26beginner
Menu-Driven Calculator
Switch Statement

Displays a numbered menu, then performs the arithmetic operation the user selects.

View Program →
27beginner
Print Cubes From 1 to N
Loops

Prints the cube of every number from 1 up to a given limit.

View Program →
28beginner
Print Day of Week
Switch Statement

Prints the name of the day corresponding to a given number.

View Program →
29beginner
Print Even Numbers
Loops

Prints every even number from 2 up to a given limit.

View Program →
30beginner
Print Month Name
Switch Statement

Prints the name of the month corresponding to a given number.

View Program →
31beginner
Print Multiplication Table
Loops

Prints the multiplication table of a given number, from 1 to 10.

View Program →
32beginner
Print Numbers 1 to N
Loops

Prints every number from 1 up to a given limit.

View Program →
33beginner
Print Numbers N to 1
Loops

Prints every number from a given limit down to 1.

View Program →
34beginner
Print Odd Numbers
Loops

Prints every odd number from 1 up to a given limit.

View Program →
35beginner
Print Squares From 1 to N
Loops

Prints the square of every number from 1 up to a given limit.

View Program →
36beginner
Product of Digits
Loops

Multiplies together every digit of a given number.

View Program →
37beginner
Remove Last Digit
Loops

Removes the last digit of a number using integer division.

View Program →
38beginner
Restaurant Menu Using Switch
Switch Statement

Looks up a menu item's name and price for a given menu choice.

View Program →
39beginner
Reverse a Number
Loops

Reverses the order of a number's digits.

View Program →
40beginner
Season Finder Using Switch
Switch Statement

Determines the season for a given month using grouped switch cases.

View Program →
41beginner
Simple Calculator Using Switch
Switch Statement

Performs basic arithmetic by switching directly on the operator symbol.

View Program →
42beginner
Sum of Digits
Loops

Adds together every digit of a given number.

View Program →
43beginner
Sum of Even Numbers
Loops

Adds up every even number from 2 up to a given limit.

View Program →
44beginner
Sum of First N Numbers
Loops

Adds up every number from 1 to a given limit.

View Program →
45beginner
Sum of Odd Numbers
Loops

Adds up every odd number from 1 up to a given limit.

View Program →
46beginner
Traffic Signal Using Switch
Switch Statement

Prints the driving action for a given traffic signal color.

View Program →
Intermediate
47intermediate
Area Calculator Using Switch
Switch Statement

Calculates the area of a shape by switching on its name.

View Program →
48intermediate
Calculate Bonus Based on Salary
Conditional Statements

Calculates an employee bonus using bracket-based bonus percentages.

View Program →
49intermediate
Calculate Digital Root
Loops

Reduces a number down to a single digit by repeatedly summing its digits.

View Program →
50intermediate
Calculate Discount Based on Amount
Conditional Statements

Calculates a discount and final payable amount using bracket-based discount percentages.

View Program →
51intermediate
Calculate Electricity Bill Using Conditions
Conditional Statements

Calculates an electricity bill using simplified, illustrative tiered per-unit rates.

View Program →
52intermediate
Calculate Income Tax
Conditional Statements

Calculates income tax using a simplified, illustrative slab structure.

View Program →
53intermediate
Calculate Power Without Math.pow()
Loops

Raises a number to a given exponent using a loop instead of Math.pow().

View Program →
54intermediate
Check Driving Eligibility
Conditional Statements

Determines whether a person meets the minimum age required to drive a given vehicle type.

View Program →
55intermediate
Check Leap Year
Conditional Statements

Determines whether a given year is a leap year.

View Program →
56intermediate
Check Number Disarium
Loops

Determines whether the sum of a number's digits, each raised to its own position, equals the number itself.

View Program →
57intermediate
Check Number Spy
Loops

Determines whether the sum of a number's digits equals the product of its digits.

View Program →
58intermediate
Check Prime Number
Math

Determines whether a given number is prime.

View Program →
59intermediate
Check Triangle Type
Conditional Statements

Classifies a triangle as equilateral, isosceles, or scalene based on its side lengths.

View Program →
60intermediate
Convert Units Using Switch
Switch Statement

Converts a value between units by switching on the requested conversion type.

View Program →
61intermediate
Currency Converter Using Switch
Switch Statement

Converts an amount from a source currency to a target currency using illustrative fixed exchange rates.

View Program →
62intermediate
Find Grade From Marks
Conditional Statements

Assigns a letter grade based on a student's marks.

View Program →
63intermediate
Find Largest of Three Numbers
Conditional Statements

Determines which of three given numbers is the largest.

View Program →
64intermediate
Find Number of Days in Month
Switch Statement

Finds how many days a given month has, accounting for leap years.

View Program →
65intermediate
Find Smallest of Three Numbers
Conditional Statements

Determines which of three given numbers is the smallest.

View Program →
66intermediate
Number to Word Using Switch
Switch Statement

Converts each digit of a number into its spoken word form.

View Program →
67intermediate
Print Tables From 1 to 10
Loops

Prints the complete multiplication tables for every number from 1 to 10.

View Program →
68intermediate
Simple ATM Menu
Switch Statement

Performs a balance check, deposit, or withdrawal based on a menu choice.

View Program →