Java Programs›Basics & I/O

👋Java Basics & I/O Programs

New to Java? These programs cover the fundamentals in small, runnable steps: printing output, reading input with Scanner, working with variables and operators, and converting between types. Each one runs online, so you can experiment straight away.55 programs · each with full code, output and a step-by-step explanation

Most Asked in Interviews

🔍
Beginner
01beginner
Add Two Numbers
Arithmetic

Adds two fixed integers and prints the result.

View Program →
02beginner
Calculate Age
Arithmetic

Finds a person's age in years from their birth year and the current year.

View Program →
03beginner
Calculate Area of Circle
Geometry

Computes the area of a circle from its radius using the formula π × r².

View Program →
04beginner
Calculate Area of Rectangle
Geometry

Computes the area of a rectangle from its length and width.

View Program →
05beginner
Calculate Area of Triangle
Geometry

Computes the area of a triangle from its base and height.

View Program →
06beginner
Calculate Average of Numbers
Arithmetic

Finds the average of a handful of individual numbers, without using an array or a loop.

View Program →
07beginner
Calculate BMI
Calculation

Computes body mass index from weight and height, then labels it with its category.

View Program →
08beginner
Calculate Circumference of Circle
Geometry

Computes the circumference of a circle from its radius using the formula 2 × π × r.

View Program →
09beginner
Calculate Discount Amount
Arithmetic

Computes a discount amount by applying a single flat discount percentage to a price.

View Program →
10beginner
Calculate Electricity Bill
Arithmetic

Computes an electricity bill by multiplying units consumed by a single flat rate per unit.

View Program →
11beginner
Calculate Gross Salary
Arithmetic

Computes gross salary by summing basic pay, HRA, DA, and other fixed allowances.

View Program →
12beginner
Calculate Percentage
Arithmetic

Computes what percentage one value is of another, such as marks obtained out of total marks.

View Program →
13beginner
Calculate Perimeter of Rectangle
Geometry

Computes the perimeter of a rectangle from its length and width.

View Program →
14beginner
Calculate Remainder
Arithmetic

Finds the remainder left over when one integer is divided by another.

View Program →
15beginner
Calculate Salary
Arithmetic

Computes pay by multiplying an hourly rate by the number of hours worked.

View Program →
16beginner
Calculate Simple Interest
Arithmetic

Computes simple interest from a principal amount, annual rate, and time in years.

View Program →
17beginner
Convert Celsius to Fahrenheit
Conversions

Converts a temperature from Celsius to Fahrenheit using the standard formula.

View Program →
18beginner
Convert char to int
Type Conversion

Shows the two meanings of char-to-int conversion: a character's code versus a digit's numeric value.

View Program →
19beginner
Convert Fahrenheit to Celsius
Conversions

Converts a temperature from Fahrenheit to Celsius using the standard formula.

View Program →
20beginner
Convert int to String
Type Conversion

Compares three common ways of turning an int into a String and checks that they agree.

View Program →
21beginner
Convert Kilometers to Miles
Conversions

Converts a distance from kilometers to miles using the standard conversion factor.

View Program →
22beginner
Convert Miles to Kilometers
Conversions

Converts a distance from miles to kilometers using the standard conversion factor.

View Program →
23beginner
Convert String to int
Type Conversion

Parses text into an int with Integer.parseInt, handling input that isn't a valid number.

View Program →
24beginner
Demonstrate Arithmetic Operators
Operators

Applies each arithmetic operator — plus, minus, times, divide, and modulo — to the same two numbers.

View Program →
25beginner
Demonstrate Assignment Operators
Operators

Applies the simple and compound assignment operators to the same variable, step by step.

View Program →
26beginner
Demonstrate Bitwise AND
Operators

Applies the bitwise AND operator to two integers and shows the result at the bit level.

View Program →
27beginner
Demonstrate Bitwise NOT
Operators

Applies the bitwise NOT (complement) operator to an integer and explains why the result is negative.

View Program →
28beginner
Demonstrate Bitwise OR
Operators

Applies the bitwise OR operator to two integers and shows the result at the bit level.

View Program →
29beginner
Demonstrate Bitwise XOR
Operators

Applies the bitwise XOR operator to two integers and shows the result at the bit level.

View Program →
30beginner
Demonstrate Left Shift
Operators

Applies the left shift operator to an integer and shows how each shift doubles its value.

View Program →
31beginner
Demonstrate Logical Operators
Operators

Applies the logical AND, OR, and NOT operators to two boolean values.

View Program →
32beginner
Demonstrate Relational Operators
Operators

Applies each relational operator to the same two numbers and prints the boolean result.

View Program →
33beginner
Demonstrate Right Shift
Operators

Applies the signed right shift operator to a negative integer and shows how the sign bit is preserved.

View Program →
34beginner
Demonstrate Ternary Operator
Operators

Uses the ternary operator to pick the larger of two numbers in a single expression.

View Program →
35beginner
Demonstrate Unary Operators
Operators

Applies unary plus, unary minus, and pre/post increment and decrement to a single variable.

View Program →
36beginner
Divide Two Numbers
Arithmetic

Divides one fixed integer by another and prints the result.

View Program →
37beginner
Hello, World
Fundamentals

The first program every Java developer writes.

View Program →
38beginner
Multiply Two Numbers
Arithmetic

Multiplies two fixed integers and prints the result.

View Program →
39beginner
Print Multiple Lines
Fundamentals

Prints several lines of text to the console.

View Program →
40beginner
Print Name
Fundamentals

Stores a name in a variable and prints it to the console.

View Program →
41beginner
Read Double From User
I/O

Reads a single decimal number typed by the user and prints it back.

View Program →
42beginner
Read Integer From User
I/O

Reads a single integer typed by the user and prints it back.

View Program →
43beginner
Read Multiple Values
I/O

Reads an int, a double, and a String from the console in a single program.

View Program →
44beginner
Read String From User
I/O

Reads a full line of text typed by the user and prints it back.

View Program →
45beginner
Subtract Two Numbers
Arithmetic

Subtracts one fixed integer from another and prints the result.

View Program →
46beginner
Add Two Numbers Using Scanner
I/O

Reads two integers from the console and prints their sum.

View Program →
47beginner
Swap Two Numbers Using a Third Variable
Variables

Swaps the values of two integers using a temporary third variable.

View Program →
48beginner
Swap Two Numbers Without a Third Variable
Variables

Swaps the values of two integers without using any extra storage.

View Program →