Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- public class Solution{
- public static void lonelyinteger(int[] a) {
- //this method prints the lone integer
- for(int i: a){
- if(!copy(a, i)) System.out.println(i);
- }
- }
- public static boolean copy(int[] x, int a){
- //this method returns true if an integer exists more than once in an array
- int numCount=0;
- boolean more=false;
- for(int thisnum: x){
- if(thisnum==a){
- numCount++;
- }
- }
- if(numCount>1){
- more=true;
- }
- return more;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int _a_size = Integer.parseInt(in.nextLine());
- int[] _a = new int[_a_size];//number of elements in the line
- int _a_item;
- String next = in.nextLine();
- String[] next_split = next.split(" ");
- for(int _a_i = 0; _a_i < _a_size; _a_i++) {
- _a_item = Integer.parseInt(next_split[_a_i]);
- _a[_a_i] = _a_item;
- }
- lonelyinteger(_a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement