【程序 32 左移右移】
题目:取一个整数 a 从右端开始的 4~7 位。
程序分析:可以这样考虑:
源码:
package com.homework.test;
import java.util.Scanner;
/*
【程序 32 左移右移】
题目:取一个整数 a 从右端开始的 4~7 位。
程序分析:可以这样考虑:
*/
public class Test32 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个大于1000000的数:");
long n = scan.nextLong(); //123 4567 8910 ——>0198 7654 321
long[] a = new long[30];
int i = 0;
while (n != 0) {
a[i] = n % 10;
// System.out.print(n%10);
i++;
n /= 10;
}
// for (int j=0; j<i; j++)
// System.out.print(a[j]);
for (int j = 3; j <= 6; j++)//123 4567 8 ——> 876 5432 1
System.out.print(a[j] + " ");
System.out.println();
}
}