Created
October 7, 2018 17:11
-
-
Save Gzoref/d3e373de9217f04a3d1db465c29280b5 to your computer and use it in GitHub Desktop.
String Manipulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Name: Geoffrey Zoref | |
* Date: 10/7/2018 | |
* Project: Text Processing and Wrapper Classes | |
*/ | |
import java.util.Scanner; | |
public class CaseManipulation { | |
public static String upperCase(String str) { | |
String result = " "; | |
for (int i = 0; i < str.length() - 1; i++) { | |
char charTemp = str.charAt(i); | |
char charUpper = Character.toUpperCase(charTemp); | |
result = result + charUpper; | |
} | |
return result; | |
} | |
public static String lowerCase(String str) { | |
String result = " "; | |
for (int i = 0; i < str.length() - 1; i++) { | |
char charTemp = str.charAt(i); | |
char charUpper = Character.toLowerCase(charTemp); | |
result = result + charUpper; | |
} | |
return result; | |
} | |
public static String camelCase(String str) { | |
String result = " "; | |
if(str.length() == 0) { | |
return result; | |
} | |
char firstChar = str.charAt(0); | |
char firstCharUpper = Character.toUpperCase(firstChar); | |
result = result + firstCharUpper; | |
for (int i = 1; i < str.length(); i++) { | |
char currentChar = str.charAt(i); | |
char previousChar = str.charAt(i - 1); | |
if(previousChar == ' ') { | |
char currentCharUpper = Character.toUpperCase(currentChar); | |
result = result + currentCharUpper; | |
}else { | |
char currentCharLower = Character.toLowerCase(currentChar); | |
result = result + currentCharLower; | |
} | |
} | |
return result; | |
} | |
public static String javaCamelCase(String s) { | |
String[] parts = s.split(" "); | |
String camelCaseString = ""; | |
for (int i = 0; i < parts.length; i++) { | |
String part = parts[i]; | |
camelCaseString = camelCaseString + toProperCase(part); | |
} | |
return camelCaseString; | |
} | |
static String toProperCase(String s) { | |
return s.substring(0, 1).toUpperCase() + | |
s.substring(1).toLowerCase(); | |
} | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("Enter String"); | |
String word1 = input.nextLine(); | |
System.out.println("Upper Case: " + upperCase(word1)); | |
System.out.println("Lower case: " + lowerCase(word1)); | |
System.out.println("CamelCase: " + camelCase(word1)); | |
System.out.println("Java Camel Case: " + javaCamelCase(word1)); | |
} | |
} | |
/** | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment