
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

1K+ Views
In this article, we will learn to check whether the number is positive or negative in Java. To check whether the specified number is positive or negative can be determined 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, we can use Java conditional statements like if-else-if blocks or ternary operators. Before that let's discuss the problem statement with the help of examples − Problem Statement Given an integer number as an input, write a Java program to check whether the number is positive ... Read More

1K+ 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

577 Views
In this article, we will learn how to find the sum of N numbers using recursion in Java. Recursion is when a method calls itself repeatedly until a base condition is met. In Java, each recursive call is placed on the stack until the base case is reached, after which values are returned to calculate the result. To solve with recursion, we need to divide our problem into smaller chunks, then find out solution for that smaller part, and that will be our base condition. In this problem, to find the sum of N numbers using recursion, we can store ... Read More

709 Views
In this article, we will understand how to find the product of two numbers using recursion in Java. A recursive function is a function that calls itself multiple times until a particular condition is satisfied. Product of two Numbers Using Recursion 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. To find the product of two numbers, let's say a and b, using recursion, the base case will be (if y = 0, ... Read More

1K+ Views
In this article, we will understand how to find the sum of the digits of a number using recursion in Java. A recursive function is a function that calls itself multiple times until a particular condition or base condition is met. 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. Problem Statement Write a program in Java to find the sum of the digits of a number using recursion. Below is a demonstration of the same. Input Enter the number : 12131415 ... Read More

594 Views
In this article, we will learn to pass a lambda expression as a method argument in Java. A lambda expression is a short block of code that takes in parameters and returns a value. Lambda Expression Lambda expressions allow passing functionality as a method parameter, reducing the need for anonymous classes. They are often used in functional interfaces, especially when working with collections and streams. Problem Statement Given an Arraylist the goal is to reverse the strings present in it. Below is a demonstration of the same − Input ("Apple", "Orange", "Grapes") Output elppA, egnarO, separG Reversing Strings in ... Read More

1K+ Views
To calculate the power of a number, Java provides different ways to do this using loops, built-in methods, and recursion. In this article, we will learn how to calculate the power of a number using recursion. In Java, Recursion is a process in which a function calls itself multiple times until it reaches a base condition, and the corresponding function is called a recursive function. Problem Statement Given a base number and a power value, we need to calculate the result of raising the base to the power using recursion. Below is a demonstration of the same. Input: Enter ... Read More

903 Views
In this article, we will understand how to find the factorial of a number using recursion in Java. The factorial of a positive number is the product of the number itself and all descending positive integers up to "n". The factorial of a negative number does not exist, and the factorial of 0 is 1. The factorial of a positive number is - factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n Factorial Using a Recursive Function A recursive function is a function that calls itself multiple times until a particular condition is satisfied. ... Read More

1K+ Views
The given task is to write a Java program to check if an integer can be expressed as the sum of two prime numbers. A number is said to be a prime if it has only two factors, which are 1 and itself, and cannot be divided by any other number. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number; all other prime numbers are odd numbers. Example Scenario Let's understand the problem with an example. The possible solution is 43 = 2 + 41. Here, 2 and ... Read More

4K+ Views
In this article, we will understand how to construct a simple calculator using switch-case. The switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.Following are the arithmetic operations we are going to perform.AdditionSubtractionMultiplicationDivisionFloor DivisionModuloBelow is a demonstration of the same −InputSuppose our input is −The two inputs: 40.0 and 12.0 Operator:%OutputThe desired output would be −The result is 40.0 % 12.0 = 4.0AlgorithmStep 1 - START Step 2 - Declare three values namely my_input_1, my_input_2 and my_result and declare a character value namely operator. Step 3 - Read the required ... Read More