Java黑皮书课后题第4章:4.22(检测子串)编写一个程序,提示用户输入两个字符串,检测第二个字符串是否是第一个字符串的子串
生活随笔
收集整理的這篇文章主要介紹了
Java黑皮书课后题第4章:4.22(检测子串)编写一个程序,提示用户输入两个字符串,检测第二个字符串是否是第一个字符串的子串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
4.22(檢測子串)編寫一個程序,提示用戶輸入兩個字符串,檢測第二個字符串是否是第一個字符串的子串
- 題目
- 題目概述
- 運行示例
- 破題:String方法、屬性的使用
- 代碼
題目
題目概述
4.22(檢測子串)編寫一個程序,提示用戶輸入兩個字符串,檢測第二個字符串是否是第一個字符串的子串
運行示例
Enter string s1: ABCD
Enter string s2: BC
BC is a substring of ABCD
Enter string s1: ABCD
Enter string s2: BDC
BDC is not a substring of ABCD
破題:String方法、屬性的使用
代碼
import java.util.Scanner;public class Test4_22 {public static void main(String[] args) {// 接收輸入Scanner input = new Scanner(System.in);System.out.println("Enter string s1: ");String s1 = input.next();System.out.println("Enter string s2: ");String s2 = input.next();// 判斷s2是否為s1子串boolean bool = s1.contains(s2);// 輸出結果if(bool)System.out.println(s2 + " is a substring of " + s1);elseSystem.out.println(s2 + " is not a substring of " + s1);} } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Java黑皮书课后题第4章:4.22(检测子串)编写一个程序,提示用户输入两个字符串,检测第二个字符串是否是第一个字符串的子串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第4章:4.20(字
- 下一篇: Java黑皮书课后题第4章:*4.23(