-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreString.java
More file actions
125 lines (115 loc) · 3.33 KB
/
Copy pathMoreString.java
File metadata and controls
125 lines (115 loc) · 3.33 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.example.MoreString;
import java.lang.reflect.Array;
public class MoreString {
public void startEnd(String n){
System.out.println(n.substring(0, 2).equals(n.substring(n.length()-2)));
}
public void contain(String n, String m){
for (int i = 0; i <= m.length()-1; i++){
boolean a = false;
System.out.print(m.charAt(i) + " ");
for (int j = 0; j <= n.length()-1; j++){
if (m.charAt(i) == n.charAt(j)){
a = true;
}
}
if (a == true){
System.out.println("yes");
}
else {
System.out.println("no");
}
}
}
public void words(String n){
int num = 1;
for (int i = 0; i <= n.length()-1; i++){
if (n.charAt(i) == ' '){
num++;
}
}
System.out.println(num);
}
public void addArray(String n){
int num = 1;
int pos = 0;
int start = 0;
int end = 0;
int count = 0;
for (int i = 0; i <= n.length()-1; i++){
if (n.charAt(i) == ' '){
num++;
}
}
String a[] = new String[num];
for (int i = 0; i <= n.length()-1; i++){
if (n.charAt(i) == ' '){
end = i;
a[pos] = n.substring(start, end);
start = i + 1;
pos++;
count++;
}
if (count == num - 1){
a[pos] = n.substring(start);
}
}
for (int i = 0; i <= num - 1; i++){
System.out.print(a[i] + " ");
}
}
public void takeEOut(String n){
String a = "";
for (int i = 0; i <= n.length()-1; i++){
if (n.charAt(i) != 'e'){
a += n.charAt(i);
}
}
System.out.println(a);
}
public void palindrome(String n){
boolean a = true;
for (int i = 0; i <= n.length()/2-1; i++){
if (n.charAt(i) != n.charAt(n.length()-1-i)){
a = false;
}
}
System.out.println(a);
}
public void longestBlock(String n){
char a = n.charAt(0);
int num = 1;
int tempNum = 1;
for (int i = 1; i <= n.length()-1; i++){
if (a == n.charAt(i)){
tempNum++;
}
if (a != n.charAt(i)){
a = n.charAt(i);
if (tempNum > num){
num = tempNum;
}
tempNum = 1;
}
}
System.out.println(num);
}
public static void main(String[]args){
MoreString runner = new MoreString();
String a = "edit";
String b = "Hello World";
String c = "leg";
String d = "I love me";
String e = "let's eat there";
String f = "madam";
String g = "ipioocd";
String h = "AP CS is for nerds";
runner.startEnd(a);
runner.contain(b, c);
runner.words(d);
runner.takeEOut(e);
runner.palindrome(f);
runner.longestBlock(g);
runner.addArray(h);
}
}