/**
* Input statement ? JAVA2 Class Fundamental Standard Edition
* Invert result ? java2 cLAss fUNDAMENTAL sTANDARD eDITION
* Reverse result ? 2AVAJ ssaLC latnemadnuF dradnatS noitidE
* Upper count ? ...
* Lower count ? ...
* Space count ? ...
* Digit count ? ...
*
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Assign {
// 문자열을 입력 받는 부분
public String getString(){
BufferedReader in = null;
String str = "" ;
System.out.print("\nInput statement\t? ");
try{
in = new BufferedReader(new InputStreamReader(System.in));
str = in.readLine();
}catch(Exception e){}
return str;
}
// Invert 구현 부분
public void Invert(String str){
char[]str2=str.toCharArray();
System.out.print("Invert result\t? ");
for(int i=0;i<str2.length;i++){
if(Character.isLowerCase(str2[i]))
{
str2[i]=Character.toUpperCase(str2[i]);
}
else if(Character.isUpperCase(str2[i]))
{
str2[i]=Character.toLowerCase(str2[i]);
}
System.out.print(str2[i]);
}
System.out.println();
}
// Reverse 구현 부분
public void Reverse(String str)
{
char[]str2=str.toCharArray();
int price=0;
System.out.print("Reverse result\t? ");
for(int i=0;i<str2.length;i++)
{
// 공백문자 인식후 Reverse
if(Character.isSpaceChar(str2[i]))
{
for(int j=i-1;j>=price;j--)
{
System.out.print(str2[j]);
}
price=i+1;
System.out.print(" ");
}
// 문자열에 저장된 마지막 단어의 경우 공백문자가 없으므로 Reverse
if((str2.length-1) == i)
for(int j=i;j>=price;j--)
{
System.out.print(str2[j]);
}
}
System.out.println();
}
// Upper Count 구현 부분
public void UpperC(String str){
char[]str2=str.toCharArray();
int count=0;
for(int i=0;i<str2.length;i++){
if(Character.isUpperCase(str2[i]))
count++;
}
System.out.println("Upper count\t? "+count);
}
// Lower Count 구현 부분
public void LowerC(String str){
char[]str2=str.toCharArray();
int count=0;
for(int i=0;i<str2.length;i++){
if(Character.isLowerCase(str2[i]))
count++;
}
System.out.println("Lower count\t? "+count);
}
// Space Count 구현 부분
public void SpaceC(String str){
char[]str2=str.toCharArray();
int count=0;
for(int i=0;i<str2.length;i++)
{
if(Character.isSpaceChar(str2[i]))
count++;
}
System.out.println("Space count\t? "+count);
}
// Digit Count 구현 부분
public void DigitC(String str){
char[]str2=str.toCharArray();
int count=0;
for(int i=0;i<str2.length;i++)
{
if(Character.isDigit(str2[i]))
count++;
}
System.out.println("Digit count\t? "+count);
}
// 모든 처리를 총괄하는 부분
public void Process(){
String str=getString();
Invert(str);
Reverse(str);
UpperC(str);
LowerC(str);
SpaceC(str);
DigitC(str);
}
}
public class Assignment5 {
public static void main(String[] args){
Assign as5=new Assign();
as5.Process();
}
}