怎么编啊,菜鸟求助
输入一个整数,如15425;,然后逆向输出52451,怎么搞啊??谢谢拉import java.util.*;
class Test{
Scanner s=new Scanner(System.in);
System.out.println("请输入一个整数");
int x=s.nextInt();
}
我写到这里就不知道怎么写了,请各位帮忙一下
搜索更多相关的解决方案:
import
----------------解决方案--------------------------------------------------------
jdk帮助文档里Scanner有详细的例子,lz可以去参考参考;
----------------解决方案--------------------------------------------------------
Scanner sc = new Scanner(System.in);
int a[]=new int[SIZE];
int i=0;
while (sc.hasNextInt()) {
a[i++]= sc.nextInt();
//......
}
----------------解决方案--------------------------------------------------------
简单的处理方法
import java.io.*;
public class Demo{
public static void main(String[] args)throws Exception{
System.out.println("输入一个整数:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String number=in.readLine();
int len=number.length();
char[] array=new char[len];
for(int i=0;i<len;i++){
array[i]=number.charAt(i);
}
for(int i=len-1;i>=0;i--)
System.out.print(array[i]);
}
}
----------------解决方案--------------------------------------------------------
用stack是最简单的。
----------------解决方案--------------------------------------------------------
String有个方法叫reverse(),直接颠倒顺序的
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
reverse();
----------------解决方案--------------------------------------------------------
reverse()
学习到了
----------------解决方案--------------------------------------------------------
学习了
----------------解决方案--------------------------------------------------------