⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkingsubstrings.java

📁 这个程序可以检查第二个字符串是不是第一个的子串,非常实用
💻 JAVA
字号:

import javax.swing.JOptionPane;
public class CheckingSubstrings {
	
	public static void main (String[] args){
		
		String s1 = JOptionPane.showInputDialog(null,"Enter the first string please!","Decimal to hex",JOptionPane.QUESTION_MESSAGE);
		
		
		
		String s2 = JOptionPane.showInputDialog(null,"Enter the second string please!","Decimal to hex",JOptionPane.QUESTION_MESSAGE);
		
		
		
	   int  a =	check(s1,s2);
		
		if(a==1)
		JOptionPane.showMessageDialog(null,"The second string is a substring of the first.","Check substring",JOptionPane.INFORMATION_MESSAGE);	
		else 
			JOptionPane.showMessageDialog(null,"The second string is not a substring of the first.","Check substring",JOptionPane.INFORMATION_MESSAGE);
	}
	
	
	public static int check(String m, String n){
		
		int k = -1;
		
		for (int i=0;i<=m.length()-1;i++ ){
			
		     if (m.charAt(i)==n.charAt(0)){
		     	int b=i;
		     	int a = 0;
		     	
		     for(int j=0;j<=n.length()-1;j++){
		     	
		          if(m.charAt(b)==n.charAt(j))
		          a++;
		          b++;	
		     	  if (b==m.length())
		     	  break ;
		     	}
		     	if (a == n.length())
		     	k=i;
		     }
		    if(k>=0)
		    break; 
		}
		
		if (k>=0)
		return 1;
		else
		return 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -