打印包含字符串的方法

方法一

import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ!!

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        //System.out.println("Line:" + line);
        String substr = sc.nextLine();
        //ArrayList ostr = new ArrayList();
        String ostr[] = new String[Integer.valueOf(line)];
        int i = 0;
        int m = 0;
        while(sc.hasNextLine()){
            String str = sc.nextLine();
            int n = str.indexOf(substr);
         //   System.out.println("n: " + n);
            if(n >= 0){
                ostr[i] = str;
               // System.out.println(ostr[i]);
                i++;
            }else{
                m++;
            }
        }
      //  System.out.println("ostr.length:" + ostr.length);
        if(ostr.length - m == 0){
            System.out.println("None");
        }else{
            for(int j = 0; j < ostr.length - m; j++){
                System.out.println(ostr[j]);
          }
        }
    }
}

方法二

 

你可能感兴趣的:(JAVASE)