File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Leetcode_August_Challenge Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Leetcode_August_Challenge ;
2
+
3
+ /*
4
+ QUESTION DETAILS:
5
+ =================
6
+ Given a word, you need to judge whether the usage of capitals in it is right or not.
7
+
8
+ We define the usage of capitals in a word to be right when one of the following cases holds:
9
+
10
+ All letters in this word are capitals, like "USA".
11
+ All letters in this word are not capitals, like "leetcode".
12
+ Only the first letter in this word is capital, like "Google".
13
+ Otherwise, we define that this word doesn't use capitals in a right way.
14
+
15
+ Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
16
+
17
+ */
18
+
19
+ public class Day1_detectCapital {
20
+
21
+ public static void main (String [] args ) {
22
+
23
+ System .out .println (detectCapitalUse ("USA" )); // true
24
+ System .out .println (detectCapitalUse ("leetcode" ));// true
25
+ System .out .println (detectCapitalUse ("Google" )); // true
26
+ System .out .println (detectCapitalUse ("FlaG" ));// false
27
+
28
+ }
29
+
30
+ public static boolean detectCapitalUse (String word ) {
31
+ if (word .equals (word .toUpperCase ())) {
32
+ return true ;
33
+ } else if (word .equals (word .toLowerCase ())) {
34
+ return true ;
35
+ } else if (Character .isUpperCase (word .charAt (0 ))
36
+ & word .substring (1 ).equals (word .substring (1 ).toLowerCase ())) {
37
+ return true ;
38
+ } else {
39
+ return false ;
40
+ }
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments