public class file {
/*检测文件中a,b所在的行数和所在的位置,
 * 例如:
 * 字符串“ffgtahtibjkli”输出
 * 1
 * 5
 * 10
 * 
 * 注意:
 * 1.要检测出所在的行数
 * 2.考虑aabb这种情况
 * 3.考虑出现多个a但是不连续的情况
 * */
public static void main(String[] args) {
	int count1=0;
	int count2=0;
	int q = 0;
	int[] t = null;
	String str2=null;
	String str1 = "asdfghjkal\nzxcvbnm\nasdfaabbnm";
	String[] len = str1.split("\n");
	//System.out.println(len.length);
	for(int i=0;i<len.length;i++) {
		str2 = len[i];
		System.out.println("这是第"+(i+1)+"行");
		for(int j = 0; j < str2.length(); j++){
			if(str2.charAt(j)=='a'){
			count1++;
			System.out.println(j+1);
				}
			if(str2.charAt(j)=='b'){
			count2++;
			System.out.println(j+1);
				}
			}
	}
	
	
	System.out.println("a共有"+count1+"个");
	System.out.println("b共有"+count2+"个");
	//System.out.println("Hello world!");
	}
}

相关文章:

  • 2021-05-21
  • 2021-12-28
  • 2022-01-25
  • 2022-12-23
  • 2021-09-20
  • 2021-09-25
猜你喜欢
  • 2021-11-29
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2021-05-25
相关资源
相似解决方案