Find the count of substrings with an odd number of 1s in its binary re
Answers
Answer:
import java . util . *;
class subc
{
public static void main(String args[])
{
Scanner sc=new Scanner(System . in);
System . out . println("Enter a string");
String a=sc . nextLine();
int l=a . length();
int count=0;
for(int i=0;i<l;i++)
{
int temp=0;
if(a . charAt(i)=='1')
{
temp++;
}
else
{
if(temp%2!=0)
{
count++;
}
temp=0;
}
}
System . out . println("The number of odd number of ones in substring are ="+ count);
}
}