forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForDebugging09.java
More file actions
110 lines (97 loc) · 2.83 KB
/
ForDebugging09.java
File metadata and controls
110 lines (97 loc) · 2.83 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
import java.util.Arrays;
/**
* Created by media on 2016-07-17.
*/
public class ForDebugging09 {
public static boolean isNextLetterBigger(String s){
if(s.charAt(0) < s.charAt(1)){
return true;
} else{
return false;
}
}
public static boolean inCharArray(char letter, char[] array){
boolean okay = false;
for(int i=0; i<array.length; i++){
if(letter == array[i]){
okay = true;
break;
}
}
return okay;
}
public static String removeLetterByIndex(String s, int index){
return s.substring(0,index) + s.substring(index+1,s.length());
}
public static boolean areTheSameLetters(char[] first, char[] second){
boolean okay = true;
if(first.length == second.length){
for(int i=0; i<first.length; i++){
if(!inCharArray(first[i], second)){
okay = false;
break;
}
}
} else{
okay = false;
}
return okay;
}
public static int numberOfOccurances(char letter, String word){
int counter = 0;
for(int i=0; i<word.length(); i++){
if(letter == word.charAt(i)){
counter++;
}
}
return counter;
}
public static boolean areTheSameOccurance(String first, String second){
boolean okay = true;
for(int i=0; i<first.length(); i++){
char tmp = first.charAt(i);
if(!(numberOfOccurances(tmp, first) == numberOfOccurances(tmp, second))){
okay = false;
}
}
return okay;
}
public static String removeLetterFromWord(char letter, String word){
int index = 0;
for(int i=0; i<word.length(); i++){
if(letter == word.charAt(i)){
index = i;
break;
}
}
if(index == word.length()-1){
return word.substring(0,index);
} else{
return word.substring(0,index) + word.substring(index+1, word.length()-1);
}
}
public static void main(String[] args){
/*
char c = 'a';
char[] array = new char[4];
array[0] = 'q';
array[1] = 'l';
array[2] = 'z';
array[3] = 'b';
//System.out.print("\nResult: " + isCharInArray(c, array));
char[] array2 = new char[3];
array2[0] = 'q';
array2[1] = 'l';
array2[2] = 'z';
//array2[3] = 'w';
/*
String s = "hakunamatata";
int i = 5;
*/
char c = 'o';
String s1 = "mamaitataa";
String s2 = "iaaaammtto";
boolean res = areTheSameOccurance(s1,s2);
System.out.print(removeLetterFromWord(c,s2));
}
}