-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroString.java
More file actions
81 lines (71 loc) · 2.04 KB
/
Copy pathIntroString.java
File metadata and controls
81 lines (71 loc) · 2.04 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.example.IntroString;
public class IntroString {
public void secondHalf(String n){
System.out.println(n.substring(n.length()/2));
}
public void concatenate(String n, String m){
String a = n.substring(1);
a += m.substring(1);
System.out.println(a);
}
public void adverb(String n){
boolean a = false;
if (n.substring(n.length()-2).equals("ly")){
a = true;
}
if (a == true){
System.out.println("yes");
}
else{
System.out.println("no");
}
}
public void contain(String n, String m){
boolean a = false;
for (int i = 0; i <= n.length() - 2; i++){
for (int j = i + 1; j <= n.length() - 1; j++){
if (n.substring(i, j).equals(m)){
a = true;
}
}
}
if (a == true){
System.out.println("yes");
}
else{
System.out.println("no");
}
}
public void backward(String n){
for (int i = n.length() - 1; i >= 0; i--){
System.out.print(n.charAt(i));
}
System.out.println();
}
public void jumble(String n){
int start = 0;
for (int i = 1; i <= n.length(); i++){
for (int j = start; j <= start + n.length() - 1; j++){
System.out.print(n.charAt(j % n.length()));
}
System.out.println();
start++;
}
}
public static void main(String[]args){
IntroString runner = new IntroString();
String a = "hi there";
String b = "hello";
String c = "there";
String d = "fast";
String e = "hippo";
String f = "hit";
String g = "hello";
runner.secondHalf(a);
runner.concatenate(b, c);
runner.adverb(d);
runner.contain(e, f);
runner.backward(g);
runner.jumble(b);
}
}