参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int value = scanner.nextInt(); int n1 = scanner.nextInt(); int n2 = scanner.nextInt(); System.out.println(getbits(value, n1, n2)); } public static int getbits(int a, int n1, int n2) { int b = 0; for(int i = n1; i <= n2; i++) b += 1 << i; return a & b; } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:567 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1008 |
C二级辅导-计负均正 (C语言代码)浏览:508 |
C语言程序设计教程(第三版)课后习题11.11 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:585 |
数组输出 (C语言代码)浏览:767 |
简单的a+b (C语言代码)浏览:644 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:677 |
Biggest Number (C++代码)回溯法浏览:1612 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:1078 |