Found 70 Articles for Java Technologies

Java program to calculate the product of two numbers

Samual Sam
Updated on 21-Jun-2024 12:47:09

12K+ Views

The * operator in Java is used to multiply two numbers. Read required numbers from the user using Scanner class and multiply these two integers using the * operator.Exampleimport java.util.Scanner; public class MultiplicationOfTwoNumbers {    public static void main(String args[]){       Scanner sc = new Scanner(System.in);       System.out.println("Enter the value of the first number ::");       int a = sc.nextInt();       System.out.println("Enter the value of the first number ::");       int b = sc.nextInt();       int result = a*b;       System.out.println("Product of the given two numbers ... Read More

Java program to reverse a string using recursion

Aishwarya Naglot
Updated on 05-Jun-2025 12:03:38

2K+ Views

In this article, we will learn to reverse a string using recursion in Java. 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 known as a recursive call of the function. You can reverse a string using the recursive function as shown in the following program. Steps to reverse a string using recursion  Following are the steps to reverse a string using recursion - Create a class called StringReverse with a method reverseString that takes ... Read More

Java program to find the average of given numbers using arrays

Lakshmi Srinivas
Updated on 13-Mar-2020 06:56:23

4K+ Views

You can read data from the user using scanner class.Using the nextInt() method of this class get the number of elements from the user.Create an empty array.Store the elements entered by the user in the array created above.Finally, Add all the elements in the array and divide the sub by the number of elements.Exampleimport java.util.Scanner; public class AverageUsingArrays {    public static void main(String args[]){       //Reading total no.of elements       Scanner sc = new Scanner(System.in);       System.out.println("Enter the number of elements/numbers");       int num = sc.nextInt();       ... Read More

Java program to Print Odd and Even Number from an Array

Shriansh Kumar
Updated on 30-Jul-2024 16:59:23

2K+ Views

Given an array of type Integer, write a Java program to find the odd and even numbers from that array. Those numbers which are completely divisible by 2 are called even numbers and if a number gives 1 as a remainder on dividing with 2 is known as odd number. Printing Odd and Even Number from an Array To print odd and even number from an array in Java, use the following ways − Using for Loop Using stream API Using for Loop In this approach, use the for ... Read More

Java program to find the 2nd smallest number in an array

Ankith Reddy
Updated on 21-Jun-2024 11:21:08

12K+ Views

To find the 2nd smallest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the 2nd element of the array.ExampleLive Demopublic class SmallestNumberInAnArray {    public static void main(String args[]){       int temp, size;       int array[] = {10, 20, 25, 63, 96, 57};       size = array.length;       for(int i = 0; i

Java program to find the largest number in an array

karthikeya Boyini
Updated on 13-Mar-2020 06:02:57

13K+ Views

To find the largest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the 1st element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray {    public static void main(String args[]){       int temp, size;       int array[] = {10, 20, 25, 63, 96, 57};       size = array.length;       for(int i = 0; i

Java program to find the 2nd largest number in an array

Samual Sam
Updated on 02-Sep-2023 15:09:09

80K+ Views

To find the second largest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the second element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray {    public static void main(String args[]){       int temp, size;       int array[] = {10, 20, 25, 63, 96, 57};       size = array.length;       for(int i = 0; i

Java program to find the 3rd largest number in an array

Arjun Thakur
Updated on 31-May-2024 17:50:35

14K+ Views

To find the third largest number of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the third element from the end of the array.ExampleLive Demopublic class ThirdLargestNumberInAnArray {    public static void main(String args[]){    int temp, size;    int array[] = {10, 20, 25, 63, 96, 57};    size = array.length;        for(int i = 0; i

Java program to implement linear search

Chandu yadav
Updated on 13-Mar-2020 05:51:22

7K+ Views

Linear search is a very simple search algorithm. In this type of search, a sequential search is done for all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.Algorithm1.Get the length of the array. 2.Get the element to be searched store it in a variable named value. 3.Compare each element of the array with the variable value. 4.In case of a match print a message saying element found. 5.else, print a message saying element not foundExampleLive Demopublic class ... Read More

Java program to print the factorial of the given number

Shriansh Kumar
Updated on 13-Sep-2024 15:55:01

5K+ Views

Given a number of type integer, write a Java program to print its factorial. The factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6). Let's understand the problem statement with examples − Example Scenario 1: Input: int n = 4; Output: res = 24 Calculation: 4! = 4 * 3 * 2 * 1 = 24 Example Scenario 2: Input: int n = 0; Output: res = 1 Factorial of 0 is always 1. Finding Factorial ... Read More

Advertisements