👋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
Adds two fixed integers and prints the result.
View Program →Finds a person's age in years from their birth year and the current year.
View Program →Computes the area of a circle from its radius using the formula π × r².
View Program →Computes the area of a rectangle from its length and width.
View Program →Computes the area of a triangle from its base and height.
View Program →Finds the average of a handful of individual numbers, without using an array or a loop.
View Program →Computes body mass index from weight and height, then labels it with its category.
View Program →Computes the circumference of a circle from its radius using the formula 2 × π × r.
View Program →Computes a discount amount by applying a single flat discount percentage to a price.
View Program →Computes an electricity bill by multiplying units consumed by a single flat rate per unit.
View Program →Computes gross salary by summing basic pay, HRA, DA, and other fixed allowances.
View Program →Computes what percentage one value is of another, such as marks obtained out of total marks.
View Program →Computes the perimeter of a rectangle from its length and width.
View Program →Finds the remainder left over when one integer is divided by another.
View Program →Computes pay by multiplying an hourly rate by the number of hours worked.
View Program →Computes simple interest from a principal amount, annual rate, and time in years.
View Program →Converts a temperature from Celsius to Fahrenheit using the standard formula.
View Program →Shows the two meanings of char-to-int conversion: a character's code versus a digit's numeric value.
View Program →Converts a temperature from Fahrenheit to Celsius using the standard formula.
View Program →Compares three common ways of turning an int into a String and checks that they agree.
View Program →Converts a distance from kilometers to miles using the standard conversion factor.
View Program →Converts a distance from miles to kilometers using the standard conversion factor.
View Program →Parses text into an int with Integer.parseInt, handling input that isn't a valid number.
View Program →Applies each arithmetic operator — plus, minus, times, divide, and modulo — to the same two numbers.
View Program →Applies the simple and compound assignment operators to the same variable, step by step.
View Program →Applies the bitwise AND operator to two integers and shows the result at the bit level.
View Program →Applies the bitwise NOT (complement) operator to an integer and explains why the result is negative.
View Program →Applies the bitwise OR operator to two integers and shows the result at the bit level.
View Program →Applies the bitwise XOR operator to two integers and shows the result at the bit level.
View Program →Applies the left shift operator to an integer and shows how each shift doubles its value.
View Program →Applies the logical AND, OR, and NOT operators to two boolean values.
View Program →Applies each relational operator to the same two numbers and prints the boolean result.
View Program →Applies the signed right shift operator to a negative integer and shows how the sign bit is preserved.
View Program →Uses the ternary operator to pick the larger of two numbers in a single expression.
View Program →Applies unary plus, unary minus, and pre/post increment and decrement to a single variable.
View Program →Divides one fixed integer by another and prints the result.
View Program →The first program every Java developer writes.
View Program →Multiplies two fixed integers and prints the result.
View Program →Prints several lines of text to the console.
View Program →Stores a name in a variable and prints it to the console.
View Program →Reads a single decimal number typed by the user and prints it back.
View Program →Reads a single integer typed by the user and prints it back.
View Program →Reads an int, a double, and a String from the console in a single program.
View Program →Reads a full line of text typed by the user and prints it back.
View Program →Subtracts one fixed integer from another and prints the result.
View Program →Reads two integers from the console and prints their sum.
View Program →Swaps the values of two integers using a temporary third variable.
View Program →Swaps the values of two integers without using any extra storage.
View Program →Computes compound interest from a principal, annual rate, and time, using Math.pow() to raise the growth factor to a power.
View Program →Evaluates a mixed expression step by step to show the order Java applies different operator types in.
View Program →Breaks a total day count down into whole years, whole months, and leftover days.
View Program →Breaks a total second count down into whole hours, whole minutes, and leftover seconds.
View Program →Proves that && skips evaluating its right-hand side entirely once the left side is already false.
View Program →Proves that || skips evaluating its right-hand side entirely once the left side is already true.
View Program →Applies the unsigned right shift operator to a negative integer and contrasts it with the signed right shift.
View Program →