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
The java.lang.Object class is the root or superclass of the class hierarchy, it belongs to the java.lang package. All predefined classes and user-defined classes are direct or indirect subclasses of the Object class. Why is Object Class a Superclass? To understand why the Object class is the superclass of every class in Java, we need to understand why a superclass is needed in the first place: To share common properties. To accept and return any type of object. Sharing Common Properties using Object Class There are 11 common properties that every ... Read More
In C/C++, Line splicing is a small feature that lets you split one long line of code into two lines by using a special symbol that is the backslash (\).Line splicing is a preprocessor feature, not a function or method. It does not have any parameters. But it simply affects how lines of code are interpreted by the preprocessor before compilation.How to Use Line Splicing? If a line of code is too long, and you want to break it into multiple lines to make it easier to read. You can use a backslash at the end ... Read More
To convert a given string into an InputStream, Java provides the ByteArrayInputStream class that is used along with a built-in method named getBytes(). While displaying a long input string, we are sometimes required to process it in smaller units. At that time, converting that string into an InputStream will be helpful. In this article, we will learn how we can use the ByteArrayInputStream class to convert a string into an InputStream with the help of example programs. Before discussing that, we need to learn about the InputStream and BufferedReader classes and the getBytes() method first: InputStream Class There are two fundamental ... Read More
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
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
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
Here is a C++ Program to get all the unique factorization of a given integer such that addition of a partition results an integer. In this program, a positive integer n is given, and we shall generate all possible unique ways to represent n as sum of positive integers. Algorithm to Perform Unique Factorization Below is the algorithm to perform the unique factorization of a given number: Begin function displayAllUniqueParts(int m): 1) Set Index of last element k in a partition to 0 ... Read More
The algebraic expression is a combination of numbers, variables (x or y), and arithmetic operators like +, -, *, and /. In this article, we'll write a C++ program to find the minimum value of an expression in the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) where a total of a+b integers are given. Our task is to split these integers into two groups, one with a numbers and the other with b numbers, and calculate the product of their sums. By trying ... Read More
The algebraic expression is a combination of numbers, variables (x or y), and arithmetic operators like +, -, *, and /. In this article, we'll write a C++ program to find the maximum value of an expression in the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) where a total of a+b integers are given. Our task is to split these integers into two groups, one with a numbers and the other with b numbers, and calculate the product of their sums. By ... Read More