Found 9326 Articles for Object Oriented Programming

Java Program to Find the Perimeter of a Rectangle

AmitDiwan
Updated on 21-Feb-2022 10:45:19

777 Views

In this article, we will understand how to find the perimeter of a rectangle. The Perimeter of a rectangle is calculated by adding the lengths of all the sides of the rectangle.Below is a demonstration of a rectangle. The perimeter of a rectangle is the total length of the two lengths and two widths of the rectangle −InputSuppose our input is −The length of the sides of a rectangle are : 5, 8, 5, 8OutputThe desired output would be −Perimeter : 26 AlgorithmStep 1 – START Step 2 – Declare 5 floating point variables a, b, c, d and perimeter ... Read More

Java Program to Calculate the Compound Interest

AmitDiwan
Updated on 21-Feb-2022 10:41:15

13K+ Views

In this article, we will understand how to calculate the Compound interest. Compound Interest is calculated using the following formula −Principle*(1+(rate / 100))^time – PrincipleCompound Interest − The percentage interest charged on principal and accrued interest. Rates are higher compared to Simple Interest.Below is a demonstration of the same −InputSuppose our input is −Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3OutputThe desired output would be −The Compound Interest is : 15762.50000000001AlgorithmStep 1 – START Step 2 – Declare four float values principle, rate, time, compound_interest Step 3 – Read ... Read More

Java Program to Calculate Simple Interest

AmitDiwan
Updated on 10-Aug-2023 12:18:20

2K+ Views

The agenda of this article is to write a Java program to calculate simple interest. But, before doing it programmatically, let's understand how we calculate simple interest mathematically. The simple interest is a technique to determine the amount of interest gained on a principal amount at the specified interest rate for a given time period. Unlike compound interest, its principal amount does not change over time. To calculate Simple Interest, we use the following formula − Simple Interest (S.I) = Principal * Time * Rate / 100 Below is a demonstration of the same − Input Enter a Principle ... Read More

Java Program to Find Even Sum of Fibonacci Series till number N

AmitDiwan
Updated on 21-Feb-2022 10:15:04

3K+ Views

In this article, we will understand how to find even sum of Fibonacci Series till number N. A Fibonacci series is sequence of numbers formed by the sum of its two previous integers. An even Fibonacci series is all the even numbers of the Fibonacci series.Fibonacci series generates the subsequent number by adding two previous numbers. Fibonacci series starts from two numbers − F0 & F1. The initial values of F0 & F1 can be taken 0, 1 or 1, 1 respectively.Fn = Fn-1 + Fn-2Hence, a Fibonacci series can look like this −F8 = 0 1 1 2 3 ... Read More

Java Program to Check whether the input number is a Neon Number

AmitDiwan
Updated on 21-Feb-2022 10:07:05

962 Views

In this article, we will understand how to check whether the input number is a neon number. A neon number is such a number whose sum of digits of square of the number is equal to the number.Below is a demonstration of the same −InputSuppose our input is −9OutputThe desired output would be the following because 92 = 81 i.e. 8 + 1 = 9The given input is a neon number AlgorithmStep1- Start Step 2- Declare an integers my_input Step 3- Prompt the user to enter an integer value/ Hardcode the integer Step 4- Read the values Step 5- Compute ... Read More

Java Program to Display Alphabets (A to Z) using loop

AmitDiwan
Updated on 21-Jun-2024 14:44:23

9K+ Views

In this article, we will understand how to print alphabets from A to Z or a to z in Java. This is accomplished using a simple for loop.Below is a demonstration of the same −InputSuppose our input is −A to ZOutputThe desired output would be −A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AlgorithmStep1- Start Step 2- Declare a character: my_temp Step 3- Run a for loop from A to Z and print the values using the increment operator Step 4- Display ... Read More

Java Program to Display All Prime Numbers from 1 to N

AmitDiwan
Updated on 31-May-2024 13:09:20

29K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Java. All possible positive numbers from 1 to infinity are called natural numbers. Prime numbers are special numbers who have only two factors 1 and itself and cannot be divided by any other number.A number is a prime number if its only factors are 1 and itself. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13 and so on. 2 is the only even prime number. All ... Read More

Java Program to Add Two Complex numbers

AmitDiwan
Updated on 21-Feb-2022 09:36:30

2K+ Views

In this article, we will understand how to add two complex numbers in Java. They have the ‘I’ that is, an imaginary part associated with it.Below is a demonstration of the same −InputSuppose our input is −15 +i24 and 3 +i7OutputThe desired output would be −18 +i31 AlgorithmStep1- Start Step 2- Declare three Complex numbers: my_input_1, my_input_2 and my_result Step 3- Hardcode the complex number values Step 4- Define a function add_complex_number when u add the real numbers and the imaginary numbers separately and return the result. Step 5- Store the result in my_result variable. Step 6- Display the result ... Read More

Java Program to Add Two Binary Strings

AmitDiwan
Updated on 21-Feb-2022 09:29:41

3K+ Views

In this article, we will understand how to add two binary strings in Java. A binary string is a sequence of numbers represented in bytes 0s and 1s.Below is a demonstration of the same −InputSuppose our input is −10101 10001OutputThe desired output would be −100110 AlgorithmStep 1- START Step 2- Create new scanner object Step 3- Enter two binary inputs Step 4- Define a carry flag Step 5- Use while condition to check if they are equal to 0 Step 6- If not, use the % operator and the carry flag to perform bitwise addition Step 7-Display it as result ... Read More

Java Program to Get Input from the User

AmitDiwan
Updated on 21-Feb-2022 08:02:00

2K+ Views

In this article, we will understand how to get an input from user in Java. This achieved using a scanner object. The Scanner.nextInt() method is used to get the input.The java.util.Scanner.nextInt() method Scans the next token of the input as an int. An invocation of this method of the form nextInt() behaves in exactly the same way as the invocation nextInt(radix), where radix is the default radix of this scanner.Below is a demonstration of the same −InputSuppose our input is −Hello, I am John!OutputThe desired output would be −The input string is: Hello, I am John! AlgorithmStep1- Start Step 2- ... Read More

Advertisements