We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 6: Let's Review
  5. Discussions

Day 6: Let's Review

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

    You are viewing a single comment's thread. Return to all comments →

  • barunkr0801
    2 months ago+ 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();
            }
      }
    }
     
    
    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy