To beyond 转换为:oT dnoyeb

//和要求不完全一样,还不能实现带标点的如To be. 会变成oT .eb,而不是oT eb.

class daoxu{
 public static void main(String[] args){
  int i=0;//句中第i+1个单词
  int j=0;//单词里的第j+1个字母
  int k=0;
  char[] ch1=new char[10];//存放单词里字母的数组
  char[] ch2=new char[10];
  String text="To beyond";
  String[] word=text.split("[ ]");
  String[] wordnew=new String[10];
  System.out.println("一共有"+word.length+"个单词");
  for (i=0;i<word.length;i++){
   //System.out.println("word["+i+"] is "+word[i]+" ");
  }
  
  //System.out.print("To".charAt(0));
  
  for(i=0;i<word.length;i++){
   int len = word[i].length();
   //System.out.println("word["+i+"].len is "+len+"  ");
  for(j=0;j<len;j++){
   //System.out.println("word["+i+"] is "+word[i]);
   ch1[j]=word[i].charAt(j);
   //System.out.println("原来字母为"+ch1[j]);
  }
  
      wordnew[i]="";
   for (k=0;k<len;k++){
    ch2[k]=ch1[word[i].length()-k-1];
    //System.out.println("逆向后"+ch2[k]);
    
    wordnew[i]+=Character.toString(ch2[k]);
    
    }
   System.out.print(wordnew[i]+" ");
 }
  
 }
}

 

运行结果:

一共有2个单词
oT dnoyeb

 

-------------------------------------------------------------------------------

 

String text="To beyond";改成String text="To beyond.";

运行结果:

一共有2个单词
oT .dnoyeb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值