-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarmup.java
More file actions
53 lines (52 loc) · 1.44 KB
/
Copy pathWarmup.java
File metadata and controls
53 lines (52 loc) · 1.44 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
import java.util.Scanner;
public class Warmup {
public static String wordFinder(String sentence, int number) {
int size=1;
for(int i=0;i<sentence.length();i++){
if(sentence.charAt(i)==' ') size++;
}
String[] str=sentence.split(" ",size);
if(size<number){
return "Number = "+number+" is out Of Bound";
}else{
return str[number-1];
}
}
public static int oddEvenCounter(String number, boolean searchForEven) {
int even=0;
int odd=0;
for(int i=0;i<number.length();i++){
if(number.charAt(i)%2==0){
even++;
}else {
odd++;
}
}
if(searchForEven){
return even;
}else {
return odd;
}
}
public static String firstWord(String wordA, String wordB) {
if(wordB.length()<wordA.length()){
String t;
t=wordA;
wordA=wordB;
wordB=t;
}
String ans="test";
for (int i = 0; i < wordA.length(); i++) {
if (wordB.charAt(i) > wordA.charAt(i)) {
ans = wordA;
break;
} else if (wordB.charAt(i) == wordA.charAt(i)) {
continue;
}else if(wordB.charAt(i)<wordA.charAt(i )){
ans = wordB;
break;
}
}
return ans;
}
}