一串数字,如何颠倒过来,如:32456变成65423,求指点
Java code
import java.util.Scanner;
public class Reverse
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("pLease in put a number:");
int number=sc.nextInt();
StringBuffer sb=new StringBuffer(""+number);
sb.reverse();
System.out.println(sb.toString());
}
}
int a[] = {3,2,4,5,6};
int b[] 元旦祝福语= new b[5];
for(int i=0;i<a.length;i++){
b[i] = a[a.length-1];
}
这样应该就可以了
StringBuffer sb=new StringBuffer("123456789");
sb.reverse();
System.out.println(sb.toString());
public static void main(String[] args) {
Scanner scan = new Scanner(System.in); //从控制台读取
String scanReverse = new StringBuilder(scan.next()).reverse().toString();//scan.next()获取输入字符串,StringBuilder自带有reverse方法
System.out.println(scanReverse);
}