/*
ChangeStringCase
Problem Statement
Given a string as input, the expected output is a string where the case of all alphabets has been changed.
*/
package Module2.module2a.module2c;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
/**
*
* @author SUNIL
*/
public class ChangeStringCase {
static String testcase1 = "Trisect";
public static void main(String args[]){
ChangeStringCase testInstance= new ChangeStringCase();
String result = testInstance.changeCase(testcase1);
System.out.println(result);
}
public String changeCase(String sentence){
String newString="";
for(int i=0;i<(sentence.length());i++){
//if(sentence.charAt(i)>=65&&sentence.charAt(i)<=90){
char eachChar=sentence.charAt(i);
if(isUpperCase(eachChar)){
System.out.println("AAAA"+i);
char changedCase=Character.toLowerCase(sentence.charAt(i));
newString=newString+changedCase;
}
else if(isLowerCase(eachChar)){
System.out.println("aaaaaa"+i);
char changedCase=Character.toUpperCase(sentence.charAt(i));
newString=newString+changedCase;
}
else{
char digit=sentence.charAt(i);
newString=newString+digit;
}
}
return newString;
}
}
ChangeStringCase
Problem Statement
Given a string as input, the expected output is a string where the case of all alphabets has been changed.
*/
package Module2.module2a.module2c;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
/**
*
* @author SUNIL
*/
public class ChangeStringCase {
static String testcase1 = "Trisect";
public static void main(String args[]){
ChangeStringCase testInstance= new ChangeStringCase();
String result = testInstance.changeCase(testcase1);
System.out.println(result);
}
public String changeCase(String sentence){
String newString="";
for(int i=0;i<(sentence.length());i++){
//if(sentence.charAt(i)>=65&&sentence.charAt(i)<=90){
char eachChar=sentence.charAt(i);
if(isUpperCase(eachChar)){
System.out.println("AAAA"+i);
char changedCase=Character.toLowerCase(sentence.charAt(i));
newString=newString+changedCase;
}
else if(isLowerCase(eachChar)){
System.out.println("aaaaaa"+i);
char changedCase=Character.toUpperCase(sentence.charAt(i));
newString=newString+changedCase;
}
else{
char digit=sentence.charAt(i);
newString=newString+digit;
}
}
return newString;
}
}
No comments:
Post a Comment