Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Q27 Search string within another string
- import java.util.*;
- public class Main
- {
- public static void main(String[] args) {
- Scanner sc= new Scanner(System.in);
- System.out.println("Enter the exhaustive string");
- String s1 =sc.nextLine();
- System.out.println("Enter the string you want to search");
- String s2 =sc.nextLine();
- int j=0;
- for(int i=0 ; i<s1.length() ; i++){
- if(s1.charAt(i)==s2.charAt(0)){
- for(int j=0 ; j<s2.length() ; j++ ){
- if(s1.charAt(i)!=s2.charAt(j)){
- check = false;
- break;
- }
- i++;
- }
- break;
- }
- if(s1.charAt(i)==s2.charAt(j)){
- j++;
- }
- }
- if(j>=s2.length()){
- System.out.println("First string does not contain second string");
- }
- else{
- System.out.println("First string contain second string");
- }
- }
- }
Add Comment
Please, Sign In to add comment