Found 2616 Articles for Java

Find First and Last Word of a File Containing String in Java

Mr. Satyabrata
Updated on 11-Jan-2023 11:09:40

5K+ Views

As per the problem statement, we need to find the first and last word of the given String. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose there is String “Java is a well-known high-level, class-based object-oriented programming language that Sun Microsystems created and first distributed in 1995. Over 3 billion devices run Java, which is currently owned by Oracle” After printing the first and last word of this String i.e “Java” and “Oracle”. Instance-2 Suppose there is String “For the creation of their desktop, web, ... Read More

Separate Odd and Even Elements into Two Separate Arrays in Java

Mr. Satyabrata
Updated on 11-Jan-2023 11:05:28

6K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to separate odd and even elements into two separate arrays and print the result. A number is said to be an even number if it is divisible by 2, else the number is an odd number. Note − The array must be an integer array. In this article, you will see how to separate even and odd numbers of an array into two different arrays by using Java programming language. Let’s start. To Show ... Read More

Increment Negative and Decrement Positive Numbers by 1 in an Array in Java

Mr. Satyabrata
Updated on 05-Jan-2023 15:25:40

951 Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to increment all negative numbers by 1 and decrement all positive numbers by 1. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the original array is {12, 21, -31, -14, 56, 16, 17, -18, 9} After updating the array element are: -30 -17 -13 8 11 15 16 20 55 (sorted) Instance-2 Suppose the original array is {19, ... Read More

How to Remove Odd Numbers from Array in Java?

Mr. Satyabrata
Updated on 05-Jan-2023 15:20:49

2K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to delete or eliminate the odd numbers present in the array and print the even array. Note − The array must be an integer array. A number is said to be an odd number if the array is not divisible by 2. In this article, you will see how to remove odd numbers from an array by using Java programming language. Let’s explore. To Show You Some Instances Instance-1 Suppose the original array is ... Read More

How to Remove Even Numbers from Array in Java?

Mr. Satyabrata
Updated on 05-Jan-2023 15:18:40

3K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to delete or eliminate the even numbers present in the array and print the odd array. Note − The array must be an integer array. A number is said to be an even number if the number is divisible by 2. In this article, you will see how to remove even numbers from an array by using Java programming language. Let’s explore. To Show You Some Instances Instance-1 Suppose the original array is {2, ... Read More

Print the Elements of an Array Present in Odd Positions in Java

Mr. Satyabrata
Updated on 05-Jan-2023 14:48:46

790 Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the array elements which are present in the odd position in an array and print them. A number is said to be even if it is divisible by 2 else it is called an odd number. Note − The array must be an integer array. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the original array is ... Read More

Print Even Positions Elements from an Array in Java

Mr. Satyabrata
Updated on 05-Jan-2023 14:47:00

2K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the array elements which are present in the even position in an array and print them. A number is said to be even if it is divisible by 2 else it is called an odd number. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the original array is {12, 5, 77, 14, 91, 21, 1, 50} ... Read More

Get the Most Frequent Element in an Array in Java

Mr. Satyabrata
Updated on 05-Jan-2023 14:42:43

17K+ Views

In Java, Array is a non-primitive data type which stores values of similar data type. As per the problem statement we have to detect which element is repeated maximum times in an array for maximum number of times and print its frequency. An array can contain duplicate values as well. So, the number of times an element is present in an array, that is called frequency of the element in the array. And the element whose frequency is more that is the most frequent element in the array. Let’s see how we can do it by using the Java programming ... Read More

How to Find the Union of Two Arrays in Java?

Mr. Satyabrata
Updated on 05-Jan-2023 14:37:07

5K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the union of two arrays. Union refers to joining together whereas union of arrays refers to the new array combining all unique elements from the input arrays. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the first array is {0, 3, 5, 6, 9, 1}. And the second array is {1, 2, 6, 10, 8, 7}. ... Read More

Find the Middle Element of an array in JAVA

Mr. Satyabrata
Updated on 05-Jan-2023 14:30:00

11K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the element which is present in the middle of the array. If the array contains odd number of elements, then you will get one element present at the exact middle of the array. If the array contains even number of elements, then you will get two elements present at the middle of the array. In this article, you will see how to get the middle element of an array by using Java ... Read More

Advertisements