Java: Find a number that appears only once in a given array of integers, all numbers occur twice
Single Occurrence Number
Write a Java program to find a number that appears only once in a given array of integers. All numbers occur twice.
Example: {10,2,38,23,38,23,21}
Output: 23
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
Source Array : [10, 20, 10, 20, 30, 40, 40, 30, 50] 50 appears only once
Flowchart:
For more Practice: Solve these Related Problems:
- Modify the program to find two numbers that appear only once.
- Write a program to find the single number using XOR.
- Modify the program to find a unique number when all others appear thrice.
- Write a program to find the first non-repeating number in an array.
Go to:
PREV : Median of Array.
NEXT : Max Depth of Binary Tree.
Java Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.