# Category Archives: Core Java

We will discuss commonly asked questions related to java 8 , exception handling, string operations, java io etc.

## Check given number is palindrome using java (non-recursive/example)

What is palindromic number ? Number which remains the same even if number is reversed. e.g. 121, 12321 etc. are palindromic numbers. Given a number, check given number is palindrome or not. We will use iterative or non recursive algorithm to check given number is palindrome. Examples of palindromic & non-palindromic numbers are as follows:… Read More »

## Find area & perimeter of a square in java (with example)

Given a side of a square, find the area and perimeter of square. Area of square is side * side e.g if side is 5, then area of square is: Area = 5 * 5 Area = 25 Perimeter of square is 4 * side e.g if side is 5, then perimeter of square is: Perimeter = 4 * side Perimeter = 20 Program: calculate area… Read More »

## Given radius, find area & circumference of circle in java (example)

Given a radius of circle, find the area and circumference of a circle. Area of circle is PI * radius * radius. e.g if radius is 5, then area of circle is Area = 3.14 * 5 * 5 Area = 78.54 Circumference of circle is 2 * PI * radius e.g if radius is 5, then… Read More »

## Find area & perimeter of rectangle in java (with example)

Given a length and breadth of a rectangle, find the area and perimeter of rectangle. Area of rectangle is length * breadth e.g if length is 5 and breadth is 7, then area of rectangle is Area = 5 * 7 Area = 35 Perimeter of rectangle is 2 * (length + breadth) e.g if length is 5 and breadth is 7, then perimeter of rectangle is Perimeter = 2… Read More »

## Find area of triangle using base & height in java (example)

Given base & height of triangle, calculate the area of triangle. Area of triangle =  0.5 * base  * height. e.g Given base = 4 and height 6. Area of triangle = 0.5 * 4 * 6 = 12. Program: calculate area of triangle using height & base in java (example) package org.learn; import java.util.Scanner; public… Read More »

## Find area of triangle (three sides) using hero formula ( java & example)

Given three sides of triangle, find the area of triangle using hero’s formula. Suppose a, b and c are the sides of triangle. We will read the input from console using Scanner class. 1. Algorithm: find area of triangle using hero’s formula in java (example) Read the sides of triangle from console. Check given sides… Read More »

## Swap two numbers without using third or temporary variable in java

Given two numbers, swap two numbers without using third or temporary variable. We will discuss following methods to swap two positive numbers. Swap numbers using XOR method. Swap numbers using addition & subtraction. Swap numbers using multiplication & division. Let us look into the methods to swap two numbers in java. Method 1: Swap two numbers –… Read More »