Java Online Compiler
Example: NonRepeatingElementsBruteForce in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// NonRepeatingElementsBruteForce public class Main { public static void main(String[] args) { int[] arr = {5, 8, 2, 5, 8, 1, 9}; System.out.println("Non-repeating elements (Brute-Force):"); // Step 1: Iterate through each element in the array for (int i = 0; i < arr.length; i++) { boolean isRepeating = false; // Step 2: Compare the current element with all other elements for (int j = 0; j < arr.length; j++) { // Step 3: Skip self-comparison if (i != j && arr[i] == arr[j]) { isRepeating = true; break; // Found a repeat, no need to check further for this element } } // Step 4: If no repeat was found, it's a non-repeating element if (!isRepeating) { System.out.println(arr[i]); } } } }
Output
Clear
ADVERTISEMENTS