使用java分別截取字符串str1和字符串str2中的部分內容,如果截取後的兩個子串相同(不區分大小寫)會輸出“兩個子串相同”,否則輸出“兩個字串並不相同”

Java問題:使用java分別截取字符串str1和字符串str2中的部分內容,如果截取後的兩個子串相同(不區分大小寫)會輸出“兩個子串相同”,否則輸出“兩個字串並不相同”

那麼下面又到了我們的代碼時刻來一波簡單的代碼,小編打算以後可以搞點複雜的代碼分享一波,奈何現在實例還不允許,不過小編是專職的性能測試人員,有性能問題找我哦。

package project_five.src.character;

import java.util.Scanner;

public class CharacterCompare {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    Scanner str=new Scanner(System.in);
    System.out.println("輸入第一個字符串");
    String str1=str.next();
    System.out.println("輸入第二個字符串");
    String str2=str.next();
    System.out.println("輸入切割的序號");
    int n=str.nextInt();
    
    String str3=str1.substring(n);
    String str4=str2.substring(n);
    
    if(str3.equalsIgnoreCase(str4)){
    	 System.out.println("兩個子串相同");
        }
    else{
        	System.out.println("兩個子串不相同");
        }
    
	}

}

有代碼肯定就有結果展示的嘍,下面是我們的結果 

輸入第一個字符串
ghjtub
輸入第二個字符串
sghTub
輸入切割的序號

4
兩個子串相同

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章