Skip to content

Commit

Permalink
Detect Capitiol
Browse files Browse the repository at this point in the history
  • Loading branch information
PRATHAP KUDUPU authored and PRATHAP KUDUPU committed May 14, 2017
1 parent 7f60a28 commit f782e5d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
Binary file added bin/Algorithms/Strings/DetectCapitol.class
Binary file not shown.
Binary file modified bin/Algorithms/Strings/NoSegmentsInString.class
Binary file not shown.
Binary file modified bin/HomeString.class
Binary file not shown.
17 changes: 17 additions & 0 deletions src/Algorithms/Strings/DetectCapitol.java
@@ -0,0 +1,17 @@
package Algorithms.Strings;

public class DetectCapitol {
public static boolean get(String word)
{
int cnt=0;
for(char c:word.toCharArray())
//If the condition is true we are counter is incremented
if('Z' -c >= 0) cnt++;
//If the count is zero and the count and length are same and count is 1 and difference is greater than zero
return ((cnt==0 ||cnt==word.length())|| (cnt==1 && 'Z' - word.charAt(0) >=0));

}

}


1 change: 1 addition & 0 deletions src/Algorithms/Strings/NoSegmentsInString.java
Expand Up @@ -7,6 +7,7 @@ public static int get(String s)
int res=0;
for (int i=0;i<s.length();i++)
{
//This condition, we are looking for two spaces and 0 position
if(s.charAt(i)!=' ' && (i==0 || s.charAt(i-1)==' '))
{
res++;
Expand Down
14 changes: 12 additions & 2 deletions src/HomeString.java
Expand Up @@ -38,11 +38,21 @@ public static void main(String args[]){
* Input: "Hello, my name is John"
Output: 5
*/
/*
String s="Hello, my name is John";
int no=Algorithms.Strings.NoSegmentsInString.get(s);
System.out.println("Segments in string : "+ no);


*/
/**
* Detect Capitol
* Input: "Hello, my name is John"
Output: 5
*/
String s="USA";

boolean isCapitol=Algorithms.Strings.DetectCapitol.get(s);
System.out.println("Detect Capitol : "+ isCapitol);

}
}

0 comments on commit f782e5d

Please sign in to comment.