2
0

More than 1 year has passed since last update.

文字列の一致方法をJavaで実装しました

import java.util.Scanner

public class Mojikensaku1 {
   public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("検索する文字を入力してください");
        String line1 = sc.nextLine();
        System.out.println("判定する文字を入力してください");
        String line2 = sc.nextLine();
        //文字列検索結果フラグの定義
        booloean flag1 = true;
        //文字列検索チェック
        flag1 = line2.contains(line1);
        //文字列が含まれているかチェック ある場合は「DANGER」ない場合は「OK」
        if (flag1 == true) {
            System.out.println("DANGER");
        } else {
            System.out.println("OK");
        }

        sc.close();
   }
}

containsメソッドを使って文字列検索をしています。

2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0