题目:取一个整数a从右端开始的4-7位
1 public class _032FetchDigit {
2
3 public static void main(String[] args) {
4 fetchDigit();
5 }
6
7 private static void fetchDigit() {
8 Scanner scanner = new Scanner(System.in);
9 System.out.println("请输入一个7位以上的正整数: ");
10 long a = scanner.nextLong();
11
12 String string = Long.toString(a);
13 char[] c = string.toCharArray();
14
15 int j = c.length;
16
17 if (j < 7) {
18 System.out.println("输入错误!");
19 } else {
20 System.out.println("截取从右端开始的4~7位是 :"+"\n" + c[j - 4] + c[j - 5]
21 + c[j - 6] + c[j - 7]);
22 }
23 }
24 }
网友评论