similar char problem
Attachments:
Answers
Answered by
0
class solve
{
public static void main(String args[])
{
Scanner sc= new Scanner(System . in);
int arr [ ];
System . out . println("Enter the length of string");
int len=sc . nextInt();
arr =new int [ len ];
System . out . println("Enter the string");
string str=sc . next();
System . out . println("Enter number of queries to be made");
int q=sc . nextInt();
for ( int i = 0; i< q; i++)
{
int count =0;
System . out . println( "Enter the query" );
int p=sc . nextInt();
for (int j=0; j<p-1 ; j++)
{
if( str . charAt ( j ) = = str . charAt ( p-1 ) )
{
count + + ;
}
}
arr [ i ] = count;
}
for ( int i= 0; i< q; i++)
{
System . out . println (arr [ i ]);
}
}
}
Similar questions