JAVA经典算法(二十四)

题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。

package cn.ls.lanqiao;

import java.util.*;

public class Test24 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		converse(n);
		/*
		 * for (int i = n.length() - 1; i >= 0; i--) { System.out.print(n.charAt(i)); }
		 */

	}

	public static void converse(int n) {
		String s = Integer.toString(n);
		System.out.println(n + "是" + s.length() + "位数");
		char[] ch = s.toCharArray();
		for (int i = ch.length - 1; i >= 0; i--) {
			System.out.print(ch[i]);
		}
	}
}
发布了151 篇原创文章 · 获赞 164 · 访问量 9787

猜你喜欢

转载自blog.csdn.net/ls_wifi/article/details/104049815
今日推荐