-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring16.java
More file actions
38 lines (31 loc) · 1 KB
/
string16.java
File metadata and controls
38 lines (31 loc) · 1 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
import java.util.Scanner;
public class string16{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Main string: ");
String s=sc.nextLine();
System.out.println("Enter first sub-string: ");
String s1=sc.nextLine();
System.out.println("Enter second sub-string: ");
String s2=sc.nextLine();
System.out.println(s.contains(s1));
System.out.println(s.contains(s2));
int x = s.indexOf(s1);
int y = s.indexOf(s2);
if(x == - 1) {
System.out.println("Raj not found");
} else {
System.out.println("Found at index " + x);
}
if(y == - 1) {
System.out.println("dev not found");
}
else {
System.out.println("Found at index " + y);
}
if(x<y)
System.out.println(s1+" comes before "+s2);
else
System.out.println(s2+" comes before "+s1);
}
}