-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordScramble.java
99 lines (91 loc) · 2.29 KB
/
WordScramble.java
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
//Name: Prabhav P.
//Period: 1A
import java.util.Scanner;
public class WordScramble
{
public static boolean isLetterA(final char letter)
{
return (letter == 'a');
}
public static boolean hasTwoA(final String str)
{
int numA = 0;
boolean has = false;
for (int i = 0; i != str.length(); i++)
{
if (str.charAt(i) == 'a')
{
numA++;
}
if (numA == 2)
{
has = true;
break;
}
}
return has;
}
public static boolean isVowel(char letter)
{
boolean isVowel = false;
char[] vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
for (int i = 0; i != 10 && isVowel == false; i++)
{
if (letter == vowels[i])
{
isVowel = true;
}
}
return isVowel;
}
public static int numVowels(String str)
{
int numVowels = 0;
for (int i = 0; i != str.length(); i++)
{
if (isVowel(str.charAt(i)) == true)
{
numVowels++;
}
}
return numVowels;
}
public static boolean equalChars(String str, char alpha, char beta)
{
int numAlpha = 0, numBeta = 0;
for (int i = 0; i != str.length(); i++)
{
if (str.charAt(i) == alpha)
{
numAlpha++;
}
else if (str.charAt(i) == beta)
{
numBeta++;
}
}
return (numAlpha == numBeta);
}
public static boolean twoInARow(String str, char alpha)
{
boolean hello = false;
for (int i = 0; i != str.length(); i++)
{
if (str.charAt(i) == alpha && str.charAt(i + 1) == alpha)
{
hello = true;
}
}
return hello;
}
public static void main(final String[] args)
{
Scanner console = new Scanner(System.in);
System.out.println(isLetterA('a'));
System.out.println(hasTwoA("Hello, why is this a thing? I had to do it!"));
System.out.println(isVowel('i'));
System.out.println(numVowels("Hello! My name is Prabhav!"));
System.out.println(equalChars("Hello! My name is Prabhav!", 'l', 'a'));
System.out.println(twoInARow("Hello! My name is Prabhav!", 'l'));
}
}