Xin chào m.n. Em đang tự học java và có làm bài tập này trong HackerRank.
Given a string, S, of length N that is indexed from 0 to N-1 , print its  even-indexed  and  odd-indexed  characters as 2 space-separated strings on a single line.
Code của em ngồi làm như sau , em làm trên eclip thì ra được kết quả nhưng áp lên website thì nó báo lỗi như sau :
Exception in thread "main" java.util.NoSuchElementException
                                      * at java.util.Scanner.throwFor(Scanner.java:862)
                                      * at java.util.Scanner.next(Scanner.java:1371)
                                      * at Solution.nhap(Solution.java:7)
                                      * at Solution.main(Solution.java:42).
Đây là code của em: Em không hiểu sao trên eclipse thì chạy được mà hackkerrank thì không ạ? có bro có thể giải thích cho em được không ạ ? Em cám ơn .
import java.util.*;
public class Day6 {
	public static String nhap() {
		Scanner input = new Scanner(System.in);
		String a= input.next();
		return a;
	}
	public static void mangChan(String a) {
		for(int i=0; i<a.length(); i++) {
		  if(i%2==0) {
         System.out.print(a.charAt(i));
		  }
		}
	}
	public static void mangLe(String b) {
		for(int j=0; j<b.length(); j++) {
			if((j%2)!=0) {
			System.out.print(b.charAt(j));
			}
		}
	}
	public static int nhapSpace() {
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		return a;
	}
	public static void space(int a) {
		for(int i=0; i<a; i++) {
        System.out.print(" ");
	}
	}
	public static void xuongDong() {
		System.out.print("\n");
	}
	public static void main(String args[]) {
		int a = nhapSpace();
        String b = nhap();
        String c = nhap();
        mangChan(b); space(a); mangLe(b); xuongDong();
        mangChan(c); space(a); mangLe(c);
	}
  } 
      
     83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?
    83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?