reverse the word

package test;

 

import java.util.Scanner;

 

public class arraytest {

 

public static char[] getcharmethod(String a) {

 

char[] test = a.toCharArray();

return test;

 

}

 

public static char[] getreverse(char[] b) {

char[] test = new char[b.length];

 

for (int i = 0; i < b.length; i++) {

 

test[i] = b[b.length - 1 - i];

 

}

 

return test;

 

}

 

public static int getPosition(char[] a) {

int position = -1;

char kong = (char) 32;

for (char s : a) {

 

}

return position;

 

}

 

public static String revers(char []re){

 

int end = 0;

int begin=0;

String temp=null;

String outcome1="";

for (int i = 0; i < re.length; i++) {

 

if(re[i]==(char)32){

int length=i-begin;

char[]r=new char[length];

for(int j=begin;j

r[j-begin]=re[j];

 

}

char[]newr=getreverse(r);

//System.out.println("tttttttt"+newr.toString());

String outcome=String.valueOf(newr);

   System.out.println("bbbbbbbbbbbbbbbbbb"+outcome);

outcome1+=outcome;

begin=i;

 

}

 

}

 

return outcome1;

}

 

public static void main(String[] args) {

 

Scanner scan = new Scanner(System.in);

String s = scan.nextLine();

System.out.println(s);

         

char[] re = getcharmethod(s);

re=getreverse(re);

System.out.println(re);

    String ss=revers(re);

        System.out.println("the outcome is "+ss);   

}

 

}

 

你可能感兴趣的:(算法,算法)