Java Articles

Page 138 of 450

Java Program to Calculate Interest for FDs and RDs using Inheritance

Shriansh Kumar
Shriansh Kumar
Updated on 06-Jun-2025 1K+ 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 check Eligibility of TPP students for appearing in Interviews

Shriansh Kumar
Shriansh Kumar
Updated on 06-Jun-2025 366 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
Shriansh Kumar
Updated on 06-Jun-2025 653 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

Java Program to Check Armstrong Number

Shriansh Kumar
Shriansh Kumar
Updated on 06-Jun-2025 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
Shriansh Kumar
Updated on 06-Jun-2025 3K+ 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
Shriansh Kumar
Updated on 06-Jun-2025 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

How can we convert a JSONArray to String Array in Java?

Manisha Chand
Manisha Chand
Updated on 06-Jun-2025 4K+ Views

A JSONArray is a class provided by the org.json package that represents a collection of JSON values. These values can be of any type, such as strings, numbers, booleans, or even nested objects or arrays. If you do not know what JSON is, then you can read the JSON tutorial. Converting JSON Array to String ArrayWe can convert a JSONArray to String Array by using a simple loop as shown in the example below - import org.json.*; import java.util.*; public class JsonArraytoStringArrayTest { public static void main(String[] args) { ...

Read More

How To Find the Midpoint of a Line in Java?

Vivek Verma
Vivek Verma
Updated on 06-Jun-2025 3K+ Views

Midpoint of a Line The midpoint refers to a point that is exactly in the middle of the line segment, which is joined through two points. These are the endpoints of a line segment and the midpoint lying in between these two points. The following diagram will provide a better understanding: Midpoint Formula The midpoint formula is defined for the points in the coordinate axes (i.e., x and y). Let's consider (x1, y1) and (x2, y2) are the endpoints of a line segment. The midpoint will be equal to half of the sum of the x-coordinates of the two ...

Read More

How to iterate List Using Streams in Java?

Vivek Verma
Vivek Verma
Updated on 06-Jun-2025 22K+ Views

In Java, a List is an interface that stores a sequence of elements of similar type. Java provides various ways to iterate over a list, such as using a for loop, forEach loop, iterator object, stream, or forEach() method with a lambda expression. What is Stream in Java? In Java, a Stream is an interface, which represents a sequence of elements (or objects) supporting sequential and parallel aggregate operations. These operations can be used to produce the desired result. The Stream interface provides a method named stream(), which is used to create a sequential stream from the current collection (or ...

Read More

How To Find Minimum Height of the Triangle with Given Base and Area in Java?

Vivek Verma
Vivek Verma
Updated on 05-Jun-2025 835 Views

The height of a triangle is the perpendicular distance from a vertex to the line containing the opposite side (which is the base). The height is also known as altitude. What is Minimum Height? The minimum height of a triangle refers to the shortest possible altitude (perpendicular distance) from a vertex to the opposite side (base). The following diagram provides you with a clear idea of the triangle's height and its base: A triangle is a polygon (a basic shape in geometry) that has three sides and three corners. The corners, also called vertices, are zero-dimensional points, while ...

Read More
Showing 1371–1380 of 4,498 articles
« Prev 1 136 137 138 139 140 450 Next »
Advertisements