Found 9326 Articles for Object Oriented Programming

Java Program to Print the Left Triangle Star Pattern

AmitDiwan
Updated on 22-Feb-2022 12:32:38

623 Views

In this article, we will understand how to print left triangle star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −The right triangle star pattern : * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *AlgorithmStep 1 - START Step 2 - Declare three integer values namely i, j ... Read More

Java Program to Print Left Triangle Star Pattern

AmitDiwan
Updated on 22-Feb-2022 12:24:23

608 Views

In this article, we will understand how to print left triangle star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *AlgorithmStep 1 - START Step 2 - Declare three integer values namely i, j and my_input Step 3 - Read ... Read More

Java Program to Check Whether a Number is Prime or Not

AmitDiwan
Updated on 14-Jun-2024 16:43:40

9K+ Views

Prime numbers are special numbers with only two factors 1 and that number itself, they cannot be divided by any other number. Therefore, to check whether a given number is prime or not, first, we will divide the given number by all natural numbers less than or equal to it and then, we check the number of factors. If the count of factors is only two then, the given number is prime otherwise not. This way of checking prime numbers is called as factorization. Now, let's understand how we can identify if a given number is prime or not by ... Read More

Java Program to Check if two strings are anagram

AmitDiwan
Updated on 05-Jul-2024 16:17:32

2K+ Views

An anagram is a word or phrase formed by rearranging the letters of two or more words. Hence, the logic to check whether two given strings are anagram or not is as follows: Suppose there are two strings, if both strings contain the same set of letters along with the same number of letters regardless of their order, then we can say that both strings are anagram otherwise not. Now, let's understand how we can implement this logic in our Java programs to find if two strings are anagram or not. Problem Statement Before jumping to the Java programs to ... Read More

Java Program to Check Armstrong Number

AmitDiwan
Updated on 21-Jun-2024 13:03:25

9K+ 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. Hence, 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 of them. If the sum we get is equal to the original number, then it is an Armstrong number otherwise not. ... Read More

Java Program to Check if An Array Contains the Given Value

AmitDiwan
Updated on 22-Feb-2022 11:03:43

923 Views

In this article, we will understand how to check if an array contains the given value. This is accomplished by iterating upon the array elements and comparing the given input with the array elements.Below is a demonstration of the same −InputSuppose our input is −Enter the number to be searched: 25 The elements in the integer array: 15 20 25 30 35OutputThe desired output would be −The array contains the given value AlgorithmStep 1 - START Step 2 - Declare three integer values namely my_input , i, array_size. A Boolean value my_check is defined and an integer array my_array is defined ... Read More

Java Program to Check Whether a Number is Positive or Negative

AmitDiwan
Updated on 10-Aug-2023 12:53:59

580 Views

Whether the specified number is positive or negative can be defined with respect to 0. A number greater than 0 is considered a positive number whereas a number less than 0 is considered a negative number. To check whether a given number is positive or negative in Java, we can use Java conditional statements like if-else blocks or ternary operators. In this article, we are going to explore the mentioned ways to identify if a number is positive or negative with the help of Java programs. Java Program to Check Whether a Number is Positive or Negative In this ... Read More

Java Program to Check Whether a Number is Even or Odd

AmitDiwan
Updated on 22-Feb-2022 10:42:25

565 Views

In this article, we will understand how to check whether a number is even or odd. This is accomplished by checking if the given number is divisible by 2.Below is a demonstration of the same −InputSuppose our input is −Enter the number : 45OutputThe desired output would be −The number 45 is an odd number AlgorithmStep 1 - START Step 2 - Declare an integer values namely my_input. Step 3 - Read the required values from the user/ define the values Step 4 - Use the modulus operator and compute my_input % 2 value. Step 5 - If the result is 0, ... Read More

Java Program to Find Sum of N Numbers Using Recursion

AmitDiwan
Updated on 22-Feb-2022 10:38:14

394 Views

In this article, we will understand how to find sum of N numbers using recursion. A recursive function is a function that calls itself multiple times until a particular condition is satisfied.Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.Many programming languages implement recursion by means of stacks. Generally, whenever a function (caller) calls another function (callee) or itself as callee, the caller function transfers execution control to the callee. This transfer ... Read More

Java Program to Find the Product of Two Numbers Using Recursion

AmitDiwan
Updated on 22-Feb-2022 10:31:13

488 Views

In this article, we will understand how to find the product of two numbers using recursion. A recursive function is a function that calls itself multiple times until a particular condition is satisfied.Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.Many programming languages implement recursion by means of stacks. Generally, whenever a function (caller) calls another function (callee) or itself as callee, the caller function transfers execution control to the callee. This ... Read More

Advertisements