有趣的小题目

有趣的小题目

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!");
    }
}

转载于:https://www.cnblogs.com/renxiuxing/p/9345640.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值