Evil Number Java5 May 2025 | 4 min read The Evil number is another special positive whole number in Java that has an even number of 1's in its binary equivalent. Unlike Prime and Armstrong numbers, Evil number is not so popular and asked by the interviewers. The numbers which are not evil are called odious numbers. Let's some examples of evil and odious numbers.
In order to check whether the number is evil or not, we have to follow the following steps:
Note: To convert a decimal number into binary, we can use the toBinaryString() in-built method or do it manually by using the loop.Let's implement the code to check whether the number is evil or not. EvilNumberExample.java Output ![]() Let's implement one more program to get all the Evil numbers in a given range FindAllEvilNumber.java Output ![]() |
Java program to remove duplicate elements from a singly linked list
In this program, we need to remove the duplicate nodes from the given singly linked list. Original List: List after removing duplicate nodes: In the above list, node 2 is repeated thrice, and node 1 is repeated twice. Node current will point to head, and index will point...
7 min read
Java Program to prove that strings are immutable in java
Write a code to prove that strings are immutable in java? Following program demonstrate it. File: ProveStringImmutable .java public class ProveStringImmutable { public static void referenceCheck(Object x, Object y) { if (x == y) { System.out.println("Both pointing to the same reference"); } else { System.out.println("Both are pointing to different reference"); } } public static void...
1 min read
Java to Program Find 2nd Smallest Number in an array
Java Program to find Second Smallest Number in an Array We can find the second smallest number in an array in java by sorting the array and returning the 2nd element. Let's see the full example to find the second smallest number in java array. public class SecondSmallestInArrayExample{ public...
2 min read
Java Program to find the longest repeating sequence in a string
In this program, we need to find the substring which has been repeated in the original string more than once. A b D F A A b d f h In the above string, the substring bdf is the longest sequence which has been repeated twice. The algorithm of the program is given below. Algorithm main() STEP 1: START STEP 2:...
2 min read
How to convert double to int in Java
Java Convert double to int We can convert double to int in java using typecasting. To convert double data type into int, we need to perform typecasting. Typecasting in java is performed through typecast operator (datatype). Here, we are going to learn how to convert double primitive type into...
1 min read
Java Program to count the total number of vowels and consonants in a string
In this program, our task is to count the total number of vowels and consonants present in the given string. As we know that, the characters a, e, i, o, u are known as vowels in the English alphabet. Any character other than that is known...
3 min read
Java program to find the duplicate words in a string
In this program, we need to find out the duplicate words present in the string and display those words. Example: big black bug bit a big black dog on his big black nose To find the duplicate words from the string, we first split the string into...
3 min read
Reserve String without reverse() function
How to reserve a string in Java without using reverse function There are following ways to reverse a string in Java: Using for loop Using While loop Using static method Using For loop Example to reverse string in Java by using for loop In the following example, we have used for loop to...
2 min read
Java Program to left rotate the elements of an array
Program to left rotate the elements of an array In this program, we need to rotate the elements of an array towards the left by the specified number of times. In the left rotation, each element of the array will be shifted to its left by...
3 min read
Tag Content Extractor Problem in Java
It is very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to...
2 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

