Found 9321 Articles for Object Oriented Programming

Java Program to Iterate over enum

AmitDiwan
Updated on 21-Feb-2022 12:29:45

182 Views

In this article, we will understand how to iterate over enum objects. Enum is a datatype that represents a small collection of objects.Below is a demonstration of the same −InputSuppose our input is −Enum objects are defined as : red, blue, green, yellow, orangeOutputThe desired output would be −Printing the Objects: red blue green yellow orangeAlgorithmStep 1 – START Step 2 - Declare the objects of Enum function namely red, blue, green, yellow, orange Step 3 – Using a for loop, iterate over the objects of the enum function and print each object. Step 4- StopExample 1enum Enum { ... Read More

Java Program to Check if two of three Boolean variables are true

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

337 Views

In this article, we will understand how to check if two of three Boolean variables are true. Boolean variables are datatypes that can contain only true or false values.Below is a demonstration of the same −InputSuppose our input is −Input : true, true, falseOutputThe desired output would be −Result : Two of the three variables are trueAlgorithmStep 1 - START Step 2 - Declare 4 boolean values namely my_input_1, my_input_2, my_input_3 and my_result Step 3 - Read the required values from the user/ define the values Step 4 - Using an if-else condition, compare two of the three values each ... Read More

Java Program to Implement Multiple Inheritance

AmitDiwan
Updated on 21-Jun-2024 12:33:10

14K+ Views

In this article, we will understand how to implement multiple inheritance. Java does not support multiple inheritance. This means that a class cannot extend more than one class, but we can still achieve the result using the keyword 'extends'.Algorithm to Implement Multiple InheritanceStep 1 – START Step 2 – Declare three classes namely Server, connection and my_test Step 3 – Relate the classes with each other using 'extends' keyword Step-4 – Call the objects of each class from a main function. Step 5 – STOPExample 1class Server{    void my_frontend(){       System.out.println("Connection to frontend established successfully");}    } ... Read More

Java Program to Count the Number of Vowels and Consonants in a Sentence

AmitDiwan
Updated on 21-Feb-2022 11:34:59

2K+ Views

In this article, we will understand how to count the vowels and consonants in Java. Alphabets that include 'a' 'e' 'i' 'o' 'u' are called Vowels and all other alphabets are called Consonants.Below is a demonstration of the same −InputSuppose our input is −Hello, my name is CharlieOutputThe desired output would be −The number of vowels in the statement is: 8 The number of vowels in the Consonants is: 12AlgorithmStep1- Start Step 2- Declare two integers: vowels_count, consonants_count and a string my_str Step 3- Prompt the user to enter a string value/ define the string Step 4- Read the values ... Read More

Java Program to Compute Quotient and Remainder

AmitDiwan
Updated on 21-Feb-2022 11:12:33

758 Views

In this article, we will understand how to compute the quotient and reminder in Java. Quotient and Reminder is calculated using two simple formula "Quotient = Dividend / Divisor" and "Remainder = Dividend % Divisor".Given an integer a and a non-zero integer d, it can be shown that there exist unique integers q and r, such that a = qd + r and 0 ≤ r < |d|. The number q is called the quotient, while r is called the remainder.Below is a demonstration of the same −InputSuppose our input is −Dividend value: 50 Divisor: 3OutputThe desired output would be ... Read More

Java Program to Print the ASCII values

AmitDiwan
Updated on 21-Feb-2022 11:07:46

935 Views

In this article, we will understand how to print ascii values of characters. This is done by assigning the character to an integer value and printing those integer values.ASCII stands for American Standard Code for Information Interchange. There are 128 standard ASCII codes, each of which can be represented by a 7-digit binary number: 0000000 through 1111111. Extended ASCII adds an additional 128 characters that vary between computers, programs and fonts.Below is a demonstration of the same −InputSuppose our input is −Enter a character: sOutputThe desired output would be −Ascii value of s is 115 AlgorithmStep1- Start Step 2- Declare ... Read More

Java Program to convert Decimal to Octal

AmitDiwan
Updated on 21-Feb-2022 10:59:16

433 Views

In this article, we will understand how to convert decimal to octal. a Decimal number is a number whose whole number part and the fractional part is separated by a decimal point. Octal Number has a base of eight and uses the number from 0 to 7.Below is a demonstration of the same −InputSuppose our input is −Enter the decimal number : 8OutputThe desired output would be −The octal value is 10AlgorithmStep 1 - START Step 2 - Declare three integer value namely my_input, I and j and an integer array my_octal Step 3 - Read the required values from ... Read More

Java Program to Find the Perimeter of a Rectangle

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

794 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 17-Jul-2024 11:12:51

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 – Principle Compound Interest − The percentage interest charged on principal and accrued interest. Rates are higher compared to simple interest. Problem Statement Write a Java program to calculate the compound interest using the formula. Below is a demonstration of the same − Input Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3 Output The Compound Interest is : 15762.50000000001 Algorithm Below are the steps to ... 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

Advertisements