zoukankan      html  css  js  c++  java
  • 有趣的小题目

    有趣的小题目#

    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
    zxcvbnm
    asdfaabbnm";
    	String[] len = str1.split("
    ");
    	//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.10 好运气
    2021.9 抢购
    2021.8 全周期工程师
    2021.7 创业者
    2021.6 过年
    jenkins学习17
    httprunner 3.x学习18
    httprunner 3.x学习17
    python笔记57-@property源码解读与使用
    httprunner 3.x学习16
  • 原文地址:https://www.cnblogs.com/renxiuxing/p/9345640.html
Copyright © 2011-2022 走看看