-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCHECK_STRING.java
More file actions
61 lines (50 loc) · 2 KB
/
Copy pathCHECK_STRING.java
File metadata and controls
61 lines (50 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testapp;
import com.mysql.jdbc.*;
import static java.lang.System.out;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
/**
*
* @author OLAOPA
*/
public class CHECK_STRING {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Scanner scan = new Scanner(System.in);
String str= null;
String str1 = null;
String str2 = null;
out.println("Input the first string");
str1 = scan.next();
out.println("Input the second string");
str2 = scan.next();
boolean confirm = false;
String container = null;
if(str2.length()<=str1.length()){
for(int i=0; i<str1.length(); i++){
/* check if the first contains a sub-string of equal length, that starts with the first letter of the second string and ends
with the last letter of the second string. If there are such strings, compare each one to str2, to check if it equals str2.
if it does equal str2, then str2 is contained in str1.
*/
if((i+str2.length()-1)<=str1.length()){
if((str1.charAt(i)==str2.charAt(0))&& (str1.charAt(i+str2.length()-1)==str2.charAt(str2.length()-1))){
container = str1.substring(i, i+str2.length());
if(container.equals(str2)){
confirm = true;
break;
}
}
}
}
}
if(confirm == true){
out.println(str1+" contains "+str2);
}
}
}