posts - 8,  comments - 11,  trackbacks - 0

/*
  *@author 诗语江南
  *@function 将字符串反序输出(测试形如"My name is 天才"的字符串,
反序后为"才天 is name My")
  *@parameter 要反序的字符串
  *@return  反序后的字符串
  */
 public static String rev(String num){
  String[] nums = num.split(" ");
  StringBuffer sb = new StringBuffer();
  for(int i = nums.length-1; i>=0; i--){
   StringBuffer sb2 = null;
   if(nums[i].length() > 1){
    if(isContainZh(nums[i])){
     sb2 = new StringBuffer(nums[i]);
     sb2.reverse();
    }
   }
   if(sb2 != null)
    nums[i] = sb2.toString();
   sb.append(nums[i] + " ");
  }
  return sb.toString();
 }
 
 //判断一个字符串是否有汉字
 public static boolean isContainZh(String str){
  boolean b = false;
  if(str.length() > 1){
   byte[] bs = str.getBytes();
   if(bs.length != str.length()){
    b = true;
   }
  }
  return b;
 }

posted on 2007-09-24 01:27 诗语江南 阅读(3415) 评论(3)  编辑  收藏

FeedBack:
# re: 将字符串反序输出
2007-10-03 01:11 | 聆笑
晕啦!!
我是超初学的!!看不懂呀,能指教一下我吗!!我的Q是223252959
谢谢  回复  更多评论
  
# re: 将字符串反序输出
2011-01-25 15:33 | 紫喵
求教+1 qq :418966608 @聆笑
  回复  更多评论
  
# re: 将字符串反序输出
2016-01-05 15:09 | yangge
package cn.com.bochy.a;

import java.util.Scanner;

public class B{
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
String s=sc.next();
String st = "";
for(int i=s.length()-1;i>=0;i--){
String ss = String.valueOf(s.charAt(i));
st+=ss;
}
System.out.println("倒序后"+st);
}


}
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2011年1月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(2)

随笔分类

随笔档案

友情连接

搜索

  •  

最新评论

阅读排行榜

评论排行榜