• + 1 comment

    My solution is giving the error (shown below) in hackerrank. However, it's executing fine on my pc.

    Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1585) at Solution.main(Solution.java:14)

    Here is my code :-

    import java.io.*;
    import java.util.*;
     
    public class Solution {
     
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            //sc.close();
            String[] s = new String[n];
            Scanner sc1 = new Scanner(System.in);
            for(int i = 0 ; i < n ; i++){
                s[i]= new String();
                s[i] = sc1.nextLine();
            }
            for(int i = 0 ; i < n ; i++){
               int l = s[i].length();
                for(int j = 0 ; j < l ; j++){
                    System.out.print(s[i].charAt(j));
                    j++;
                }
                System.out.print(" ");
                for(int j = 1 ; j < l ; j++){
                    System.out.print(s[i].charAt(j));
                    j++;
                }
                System.out.println();
            }
      }
    }