java 数组 逆序排列

2025-01-05 08:26:25
推荐回答(2个)
回答1:

import java.util.*;
public class Ni
{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String str=sc.next();

for(int i=str.length()-1;i>=0;i--){
System.out.print(str.charAt(i));
}

}
}

回答2:

//当直接回车时候程序结束
public class Test {

/**
* @param args
*/
public static void main(String[] args) {

BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String str=null;
StringBuffer sb=null;
try{
str=bf.readLine();
sb=new StringBuffer(str);
}catch(Exception e){}
while(str.length()!=0)
{
System.out.println(sb.reverse());
try{
str=bf.readLine();
sb=new StringBuffer(str);
}catch(Exception e){}
}
}

}