Skip to content

Commit 916d267

Browse files
authored
Create TrailingString.java
1 parent 137a882 commit 916d267

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Moderate-Level/TrailingString.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
There are two strings: A and B. Print 1 if string B occurs at the end of string A. Otherwise, print 0.
3+
*/
4+
5+
import java.io.*;
6+
public class Main {
7+
public static void main (String[] args) throws IOException {
8+
File file = new File(args[0]);
9+
BufferedReader br = new BufferedReader(new FileReader(file));
10+
String line;
11+
while ((line = br.readLine()) != null) {
12+
String[] s = line.split(",");
13+
int length2 = s[1].length();
14+
int length1 = s[0].length();
15+
String s1 = "";
16+
if (s[0].length()>=s[1].length()) {
17+
s1 = s[0].substring(length1-length2, length1);
18+
}
19+
if (s1.equalsIgnoreCase(s[1])) {
20+
System.out.println("1");
21+
}
22+
else {
23+
System.out.println("0");
24+
}
25+
}
26+
br.close();
27+
}
28+
}

0 commit comments

Comments
 (0)