Java Program to Calculate Interest for FDs and RDs using Inheritance

Shriansh Kumar
Updated on 06-Jun-2025 14:04:57

881 Views

Inheritance is a concept that allows us to access the properties and behaviors of one class in another class. The class whose methods and member variables are inherited is known as the super class or parent class, and the class that inherits these methods and member variables is known as the child class or subclass. In Java, we use the extends keyword to inherit a class. Problem Statement Write Java programs that calculate interest for Fixed Deposits (FDs) and Recurring Deposits (RDs) using inheritance. The program should prompt the user to choose between FD and RD, enter the amount and duration, ... Read More

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

Shriansh Kumar
Updated on 06-Jun-2025 14:00:42

2K+ Views

To count number of vowels and consonants in a given String, we can use the switch statement and if-else condition in Java. Alphabets that include 'a' 'e' 'i' 'o' 'u' are called Vowels and all other alphabets are called Consonants. Let's understand the problem statement with an example scenario. Example Scenario Suppose our input string is: Input: Hello, my name is Charlie Output: Vowels = 8, Consonants = 12 In the given string, the collective count of vowels is 8 and consonants is 12. Using switch Statement Run a for-loop, check each letter whether it is a consonant or ... Read More

Can we create an object of an abstract class in Java?

Shriansh Kumar
Updated on 06-Jun-2025 13:59:55

15K+ Views

No, we can't create an object of an abstract class. But, we can create a reference variable of an abstract class. The reference variable is used to refer to the objects of derived classes (subclasses of abstract class). An abstract class hides the implementation and shows the function definition to the user. A Java abstract class can have instance methods that implement a default behavior and 0 or more abstract methods. A method which does not have body is known as abstract method. It contains only the method signature and an abstract keyword before it as shown below: public abstract ... Read More

Java Program to check Eligibility of TPP students for appearing in Interviews

Shriansh Kumar
Updated on 06-Jun-2025 13:58:45

315 Views

Checking Eligibility of TPP Students in Java Consider the following table for eligibility criteria of different companies for appearing in interviews: CGPA ... Read More

Java Program to Allocate and Initialize Super Class Members using Constructor

Shriansh Kumar
Updated on 06-Jun-2025 13:57:24

502 Views

In Java, super refers to the parent class instance, and to inherit members of the super class to the child class, we use the extends keyword. Before writing a Java program to allocate and initialize super class members using a constructor, let's go through some concepts we are going to use in this article. What is Constructor? A Java constructor is a class member that initializes instance variables of a class. It is very similar to a method, but the difference is that methods can return a value, but a constructor does not return any value because it can't have any return ... Read More

What is a constant and how to define constants in Java?

Shriansh Kumar
Updated on 06-Jun-2025 13:38:33

34K+ Views

Constants in Java A constant is a variable whose value cannot be changed once it has been initialized. Java doesn't have built-in support for constants. To define a variable as a constant, we just need to add the keyword "final" in front of the variable declaration. It is not mandatory that we assign values to constants during declaration. Syntax of Java Constant final float pi = 3.14f; The above statement declares the float variable "pi" as a constant with a value of 3.14f. We cannot change the value of "pi" at any point in time in the program. ... Read More

Java Program to Check Armstrong Number

Shriansh Kumar
Updated on 06-Jun-2025 13:27:53

14K+ Views

In number theory, an Armstrong number is a pattern-based number whose sum of each digit raised to the power of total number of digits is equal to the given number itself. This article aims to explain Java programs that checks whether the given number is Armstrong or not. How to Check Armstrong Number? To check whether a number is an Armstrong or not, first, determine the total number of digits and assume it 'n'. Then separate each digit and raise them to the power of 'n'. In the last step, calculate the power of each digit and add all ... Read More

Java program to check if a given number is perfect number

Shriansh Kumar
Updated on 06-Jun-2025 13:17:34

2K+ Views

When the sum of factors of a given number (after discarding the given number) is equal to the number itself is called a perfect number. The sum of these divisors is known as the aliquot sum. Therefore, we can say that a number is perfect if it matches its aliquot sum. All known perfect numbers are even. Problem Statement In this article, we will create Java programs to check if a given number is perfect or not. Let's try to understand the given problem through some examples: Example Scenarios: Input: number = 496 Output: 496 is a perfect number ... Read More

Java program to check whether a number is even or odd

Shriansh Kumar
Updated on 06-Jun-2025 13:10:00

2K+ Views

We are given an integer number as input, and our task is to write a Java program to check whether that number is even or odd. If a number is divisible by 2, then it is an even number otherwise, it is odd. To verify a given number is even or odd in Java, we can use 3 different ways one with the modulus operator (%), another with the bitwise AND operator (&), and a third one using a switch statement. Example Scenarios: Let's understand the problem statement with some example scenarios: Input: number = 45 Output: result = odd ... Read More

Java Program to Convert Decimal to Octal

Shriansh Kumar
Updated on 06-Jun-2025 13:04:10

773 Views

The octal number system has a base value of 8 as it contains digits from 0 to 7, i.e., 8. On the other hand, the decimal number system has 10 digits from 0 to 9. Hence, its base value is 10. In this article, we will learn to convert decimals to the octal number system in Java. Problem Statement The goal is to write a program to convert a given decimal number (base 10) into its equivalent octal number (base 8). Example Scenario: Input: int decimalNumber = 8 Output: The octal value is = 10 Converting Decimal to Octal in ... Read More

Advertisements