Ada and Crayon

import java.lang.*;
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
//System.out.println(“Enter n”);
int n=sc.nextInt();
for(int j=0;j<n;j++)
{
//System.out.println(“Enter String”);
//Scanner s = new Scanner(System.in);
String crayon=sc.nextLine();
char a[]=new char[crayon.length()];
a=crayon.toCharArray();
int up=0,d=0;
char com=a[0];
for(int i=1;i<a.length;)
{
while(i<a.length && a[i]==com )
i++;
if(com==‘U’)
up++;
else
d++;
if(i<a.length)
com=a[i];
}
System.out.println(Math.min(up,d));
}
}

}

i am getting NZEC error? can some one provide solution

Add this line just after you take input of n-

 String temp=sc.nextLine();

Currently, your string in loop is taking the “newline character” present after number N, which we dont want. Just get a dummy string to absorb that and go on as usual.

//