PTA 7-14 逆序输出数的各位数字 (10分)

从键盘上输入一个正整数,逆序输出该数的各位数字。 例如:输入123,输出321。

输入格式:

直接输入一个正整数,没有其它任何附加字符。

输出格式:

直接输出一结果,没有其它任何附加字符。

输入样例:

123
 

输出样例:

321

作者: 王跃萍
单位: 东北石油大学
时间限制: 400 ms
内存限制: 64 MB
代码长度限制: 16 KB
 
 1 import java.util.Scanner;
 2 public class Main {
 3     public static void main(String[] args) {
 4         Scanner sc=new Scanner(System.in);
 5         String s=sc.next();
 6         String[] a=s.split("");
 7         for(int i=a.length-1;i>=0;i--) {
 8             System.out.print(a[i]);
 9         }
10     }
11 }

猜你喜欢

转载自www.cnblogs.com/Flyfishy/p/12163968.html