字符串反转

 

/*
 * 用户输入字符串和大小写标识,如果输入true则翻转大写,flase则翻转小写,null则原样输出
 *
 */
import java.io.*;

public class OprString{
 private StringBuffer t = null;

 public String getInput(){
  BufferedReader input = null;
  String s = "";
  try{
   System.out.print("Please input the String : ");
   input= new BufferedReader(new InputStreamReader(System.in));
   s = input.readLine();
   t = new StringBuffer(s);
  }catch(IOException ioe){
   ioe.printStackTrace();
  }
  return s;
 }

 public boolean getCase(){
  boolean b = false;
  String c = "";
  try{
   System.out.print("Please input the case {true(upper) / false(lower) / null(no change)} : ");
   BufferedReader ca = new BufferedReader(new InputStreamReader(System.in));
   c = ca.readLine();
  }catch(IOException ioe){
   ioe.printStackTrace();
  }

  if(c.equals("true")){
   b = true;
  }
  else if(c.equals("false")){
   b = false;
  }
  
  else if(c.equals("null")){
   System.out.println(this.t);
   System.exit(0);
  }

  return b;
 }
 
 public String oprString(String s ,Boolean cas){
  StringBuffer sb = new StringBuffer(s);
  sb = sb.reverse();
  String tmp = sb.toString();
  boolean b = case.booleadValue();
  if(cas){
   tmp = tmp.toUpperCase();
  }
  else if(!cas){
   tmp = tmp.toLowerCase();
  }
  return tmp;
 }
}



public class Test{
 public static void main(String [] args){
  OprString os = new OprString();
  String s = os.getInput();
  boolean cas = os.getCase();
  String tmp = os.oprString(s,new Boolean(cas));
  System.out.println(tmp);
 }
}
来自:http://chenhongbin007.blog.163.com/blog/static/34069921200932781013202/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值