NoSuchElementException

whatever question m solving it always throws an exception on compile-time , but the same code runs perfectly on the local machine… why it is happening ??

Hey @87adarsh.gupta can you please share you code with me, so that I can tell you. What issue you are actually facing?

import java.util.*; public class Main { public static boolean checkDuplicates(int[] arr){ HashSet set = new HashSet<>(); for(int i=0;i<arr.length;i++){ boolean flag = set.add(arr[i]); if(!flag){ return true; } } return false; } public static void main (String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i] = sc.nextInt(); boolean res = checkDuplicates(arr); System.out.println(res); } }

can you access my code window ???

No @87adarsh.gupta I can’t . Moreover it seems to be java code and you have tagged c++ TA. I would request you to ask you doubt by tagging Java, so that right TA can tell you what’s the issue with your code. Moreover i would also suggest to run your this program on some online ide to. If the issue you are facing here is same as there, then there’s some issue in your program but if not then you can ask your doubt again :grinning:
Hope I helped you :grinning:

Is there anything else I can help you with, then do let me know :grinning:

thanks sir, actually m new to coding blocks so i didnt know about tagging the TA , thanks for suggestion , i am gonna run it on sime other IDE

It’s fine @87adarsh.gupta, happy to help :grinning: keep coding, keep learning

how can i tag a java TA

When you attach your code while asking doubt. Write java code in the description. They will see and reply to you asap :grinning:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.