Java经典编程题50道之三十二

取一个整数a从右端开始的4~7位。

public class Example32 {
    public static void main(String[] args) {
        cut(123456789);
    }

    public static void cut(long n) {
        String s = Long.toString(n);
        char[] c = s.toCharArray();
        int j = c.length;
        if (j < 7) {
            System.out.println("输入错误!");
        } else {
            System.out.println("截取从右端开始的4~7位是:" + c[j - 7] + c[j - 6]
                    + c[j - 5] + c[j - 4]);
        }
    }
}

原文地址:https://www.cnblogs.com/qubo520/p/6955782.html