-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrailingString.java
More file actions
55 lines (38 loc) · 900 Bytes
/
Copy pathTrailingString.java
File metadata and controls
55 lines (38 loc) · 900 Bytes
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
/**
*You are given two strings 'A' and 'B'. Print out a 1 if string 'B' occurs at the end of string 'A'.
*Else a zero.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class sameend {
public static void main(String[] args) {
read(args[0]);
}
public static void read(String f) {
File file = new File(f);
try {
Scanner in = new Scanner(file);
while (in.hasNext()) {
String str = in.nextLine();
System.out.println(bInA(str));
}
} catch (FileNotFoundException e) {
}
}
private static String bInA(String str) {
String[] s = str.split(",");
if(s[0].length() > s[1].length()){
return bInA(s[0], s[1]);
}
else
return "0";
}
private static String bInA(String a, String b) {
int c = a.length() - (b.length());
if(a.substring(c).equals(b)){
return "1";
}
return "0";
}
}