reverse String and char[]

reverse String and char[]
 public static void main(String[] args)
        {
                String str=" i am a student";
                char[] c=str.toCharArray();
        char[] temp=new char[c.length];
             for(int i=0,j=c.length-1;i<c.length;i++,j--){
                        temp[j]=c[i];
                                 }

     public static void main(String[] args)
        {
                String str = "I am a student";
                String[] str2 = str.split(" ");
                for(int i = str2.length - 1;i >= 0;i--)
                {
                        System.out.print(str2[i] + " ");
                }
                System.out.println();
        }

                System.out.println(temp);
        }

你可能感兴趣的:(reverse String and char[])