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 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. Algorithm to find area of triangle using hero’s formula: Read the sides of triangle from console. Check given sides of triangle can… 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 »

Program to reverse number in java – iterative method (example)

Given a input number in java. Reverse input number using iterative or non recursive algorithm. e.g. if input number is 1234 then reverse number should be 4321. We will use modulus & divide operator to reverse number. e.g 1234 % 10 = 4 1234 / 10 = 123. Reverse number using non recursive algorithm: Given… Read More »

Page 10 of 41« First...89101112...203040...Last »