Help me in solving XYSTRP problem

My issue

the question has wrong output for testcase xxxxyy output should be 2

My code

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	   Scanner k=new Scanner(System.in);
	   int t=k.nextInt();
	   k.nextLine();
	    for(int i=0;i<t;i++)
	   { 	   String gr=k.nextLine();
	          int n=gr.length();
	          int x=0;
	          int y=0;
	       
	         for(int j=0;j<n;j++)
	         {
	            if(gr.charAt(j)=='x')
	             x++;
	             else
	             y++;
	             
	         }
	         
	        if(x>=y&&y!=0)
	        System.out.println(y);
	        else{if (y>=x&&x!=0)
	        System.out.println(x);
	        else 
	        System.out.println(0);

	        
	        }
	        
	   }
	}
}

Learning course: Placement preparation: Advanced
Problem Link: Chef and String in Placement preparation: Advanced