- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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

# Java Program to Find the Number Occurring Odd Number of Times

To find the number occurring odd number of times, the Java code is as follows −

## Example

public class Demo { static int odd_occurs(int my_arr[], int arr_size){ int i; for (i = 0; i < arr_size; i++){ int count = 0; for (int j = 0; j < arr_size; j++){ if (my_arr[i] == my_arr[j]) count++; } if (count % 2 != 0) return my_arr[i]; } return -1; } public static void main(String[] args){ int my_arr[] = new int[]{ 34, 56, 99, 34, 55, 99, 90, 11, 12, 11, 11, 34 }; int arr_size = my_arr.length; System.out.println("The number that occurs odd number of times in the array is "); System.out.println(odd_occurs(my_arr, arr_size)); } }

## Output

The number that occurs odd number of times in the array is 34

A class named Demo contains a static function named ‘odd_occurs’. This function iterates through the integer array, and checks to see the number of times these numbers occur. The odd number that occurs frequently is returned as output. In the main function, an integer array is defined, and the length of the array is assigned to a variable. The function is called by passing the array, and its length as parameters. Relevant message is displayed on the console.

- Related Questions & Answers
- C/C++ Program to Find the Number Occurring Odd Number of Times?
- C/C++ Program for Finding the Number Occurring Odd Number of Times?
- Python Program to Find Element Occurring Odd Number of Times in a List
- Python program to find the number occurring odd number of times using Lambda expression and reduce function
- Find the Number Occurring Odd Number of Times using Lambda expression and reduce function in Python
- Finding number that appears for odd times - JavaScript
- Java program to find whether given number is even or odd
- Golang Program to find the odd-occurring elements in a given array
- Program to find most occurring number after k increments in python
- How to find the one integer that appears an odd number of times in a JavaScript array?
- C++ Program to calculate the number of odd days in given number of years
- Java Program to Find The Perfect Number
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- Python Program for Find sum of odd factors of a number

Advertisements