Help me to find problem in my code

problem : HTMLTAGS Problem - CodeChef
my code : CodeChef: Practical coding for everyone

for my inputs it is always giving me output as Error .

s doesn’t seem to be being read in correctly: it might be the same problem as in C++, where after you read in t, the value of sc.nextLine() will just be the rest of the line containing t i.e. the empty string.

I don’t know enough about Java’s IO to be sure, though.


This seems to work:

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
	    Scanner sc = new Scanner(;
		int t= sc.nextInt();
        sc.nextLine(); // Skip the remainder of the line containing T.
		for(int i=0 ; i<t ;i++ )
		    String s = sc.nextLine();
		    boolean b=false;
		    int n= s.length();
		        b= ( s.charAt(0) == '<' && s.charAt(1) == '/' && s.charAt(n-1) == '>' );
		        for( int j=2 ; j< n-1 ;j++)
		            if(!(Character.isLowerCase(s.charAt(j)) || Character.isDigit(s.charAt(j))))

Or maybe, the logic was incorrect here.

He wrote

for(int j = 0; j < n - 1; j++)


And btw, instead of nextLine(), he can use the next() method of Scanner Class everywhere.

Or both :slight_smile:

1 Like