Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. public class Solution{
  8. public static void lonelyinteger(int[] a) {
  9. //this method prints the lone integer
  10. for(int i: a){
  11. if(!copy(a, i)) System.out.println(i);
  12. }
  13. }
  14.  
  15. public static boolean copy(int[] x, int a){
  16. //this method returns true if an integer exists more than once in an array
  17. int numCount=0;
  18. boolean more=false;
  19. for(int thisnum: x){
  20. if(thisnum==a){
  21. numCount++;
  22. }
  23. }
  24. if(numCount>1){
  25. more=true;
  26. }
  27. return more;
  28. }
  29.  
  30. public static void main(String[] args) {
  31. Scanner in = new Scanner(System.in);
  32. int _a_size = Integer.parseInt(in.nextLine());
  33. int[] _a = new int[_a_size];//number of elements in the line
  34. int _a_item;
  35. String next = in.nextLine();
  36. String[] next_split = next.split(" ");
  37.  
  38. for(int _a_i = 0; _a_i < _a_size; _a_i++) {
  39. _a_item = Integer.parseInt(next_split[_a_i]);
  40. _a[_a_i] = _a_item;
  41. }
  42. lonelyinteger(_a);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement