【发布时间】:2021-06-23 13:22:46
【问题描述】:
JAVA
请帮我写代码。它显示 n-1 作为给定字符串的子字符串中 As 数的输出。例如,考虑一个字符串“AAABBBBBAAAAAA”,在这个字符串中,As 的最大子字符串数为 6,但我的代码显示 6-1=5。
{
public static void main (String[] args)
{
Scanner s=new Scanner(System.in);
String str=s.nextLine();
int size=str.length();
int count=0,max=0;
for(int i=0;i<=size-1;i++)
{
if(str.charAt(i)=='A')
{
count++;
max=count;
}
else
{
count--;
}
}
System.out.print(max);
}
}```
【问题讨论】: