Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sandbox.test01;
- import java.util.Scanner;
- public class Main {
- public static boolean checkArray(int [] x)
- {
- for(int i = 0; i < x.length; i++)
- {
- for(int j = 0; j < x.length; j++)
- {
- if(x[i] == x[j])
- {
- if(i != j) // make sure its not comparing the same value to itself :P
- return true;
- }
- }
- }
- return false;
- }
- public static void main(String args [])
- {
- int x [] = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8 };
- if(checkArray(x))
- System.out.println("Duplicate found!");
- else
- System.out.println("No Dupes");
- return;
- }
- }
Add Comment
Please, Sign In to add comment