Java Articles

Page 141 of 450

Java Program to Add the nth Square Series

Shriansh Kumar
Shriansh Kumar
Updated on 30-May-2025 373 Views

The sum of the nth squares series is a form of arithmetic progression where the sum of squares is arranged in a sequence with the initial term as 1, and n being the total number of terms. 12 + 22 + 32 + ... + n2 In this article, we will discuss a Java program to add the nth square series. But, before that, let's see an example scenario: Example Scenario: Input: num = 6 Output: sum = 91 It will be calculated as: 12 + 22 + 32 + 42 + 52 + 62 = 1 ...

Read More

Java Program to Add Two Matrix Using Multi-Dimensional Arrays

Shriansh Kumar
Shriansh Kumar
Updated on 30-May-2025 2K+ Views

For two given matrices, each of size m x n, we need to write a Java program to add them. Amatrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m x n matrix. Individual entries in the matrix are called elements and can be represented by a[i][j], which means that the element a is present at the ith row and jth column. Matrix is an example of multi-dimensional array. In Java, a multi-dimensional array is an array of arrays. It is used to store data within a ...

Read More

Java Program to Compute Quotient and Remainder

Shriansh Kumar
Shriansh Kumar
Updated on 30-May-2025 2K+ Views

Given an integer a and a non-zero integer d, our task is to write a Java program to compute the quotient and remainder. Quotient can be calculated using the formula "Quotient = Dividend / Divisor" and for remainder, use "Remainder = Dividend % Divisor". When a number, i.e., dividend, is divided by another number, i.e., divisor, the quotient is the result of the division, while the remainder is what is left over if the dividend does not divide completely by the divisor. Example Scenario Suppose our input is - Input1: Dividend = 50 Input2: Divisor = 3 The output ...

Read More

Java Program to Categorize Taller, Dwarf and Average by Height of a Person

Shriansh Kumar
Shriansh Kumar
Updated on 30-May-2025 584 Views

The given task is to categorize Taller, Dwarf, and Average by the Height of a Person. First of all, we need to define tall, dwarf, and average height of a person. Let us assume -A person with a height between 170cm to 195cm is considered taller.If his height is between 150cm and 195cm, he is considered taller.A person whose height is below 150cm is considered a dwarf.If his height is greater than 195cm, he is considered abnormal.Categorizing the Height of a Person in JavaTo categorize the Height of a Person, we need to compare his height with each range specified above. ...

Read More

How to print a formatted text using printf() method in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 686 Views

In Java, formatted text refers to those text that has been processed and arranged according to a specific format. According to the article, we will use the printf() method to learn how to print the formatted text. Formatted Text using printf() Method In Java, to print the formatted output or text we have a printf() method. The printf() method allows us to format output to a java.io.PrintStream or java.io.PrintWriter. These classes also contain a method called format() which can produce the same results, so whatever we read here for the printf() method can also be applied to the format() method. ...

Read More

How can we read from standard input in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 39K+ Views

The standard input (stdin) can be represented by System.in in Java. The System.in is an instance of the InputStream class. It means that all its methods work on bytes, not Strings. To read any data from a keyboard, we can use either the Reader class or the Scanner class. Using Reader Class In Java, the Reader class is an abstract class belonging to the java.io package that is used for reading character streams. It is the superclass of all character input streams, such as "BufferedReader", "InputStreamReader", "FileReader", etc. Subclasses of Reader To use the functionality of the Reader class, use its ...

Read More

How To Check Whether a Number Is a Fascinating Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 5K+ Views

What is Fascinating Numbers? A Fascinating number is a number if the result of concatenation of the (original) number with its multiples of 2 and 3 contains all the digits from 1 to 9. For example, we have the number 192. Its product with 2 is 384, and with 3 is 576. Now concatenate (don't add) these with the original number: "192" + "384" + "576" = "192384576", which contains all the digits from 1 to 9 exactly once. Here are some other fascinating numbers, suchas: 192, 1920, 2019, 327, etc. Note: For a number to be a fascinating number, ...

Read More

How To Check Whether a Number is a Evil Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 4K+ Views

What is Evil Number? In mathematical terms, an Evil number is a number whose binary representation has exactly an even number of 1's present in it. For example, the binary representation of 3 is 0011. So the number 1's is even the number 3 is an evil number. A binary number is a number expressed in the base-2 numeral system, it is also known as the binary numeral system. It is always represented using two digits: 0 and 1. Each digit (0, 1, 2, 3, ...), character (a, A, b, c, D, ...Z), and symbol (@, #, $, ...) used ...

Read More

How To Check Whether a Number Is a Bouncy Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 4K+ Views

What is Bouncy Number? In mathematical terms, a Bouncy number is a positive integer whose digits are neither in increasing nor in decreasing order. For example: 101, 102, 103, 104, 105, 106, 107, 108, 109, and 120 are the bouncy numbers, which digits does not follow any specific order. The bouncy number will always be unsorted, and there are no bouncy numbers between the range of 1 to 100 because numbers less than 100 can have only two digits that will be either increasing or decreasing order. Input & Output Scenarios The following input and output scenarios will implement the mathematical ...

Read More

Can Enum implements an interface in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 14K+ Views

Yes, an Enum implements an Interface in Java. It can be useful when we need to implement business logic that is tightly coupled with a specific property of a given object or class. Before implementing the interface with an enum, let's discuss enums and interfaces in Java with a code snippet for better understanding. Enum in Java In Java, an Enum (i.e., an enumeration) is a special data type added in Java version 1.5. Enums are constants by default; the names of an enum type's fields are in uppercase letters. In the Java programming language, you can define an Enum ...

Read More
Showing 1401–1410 of 4,498 articles
« Prev 1 139 140 141 142 143 450 Next »
Advertisements