参考代码:
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) { String s = ""; for(int i = 0; i < n2 - n1; i++) { s += "1"; } for(int i = 0; i < n1; i++) { s += "0"; } int b = Integer.parseInt(s, 2); return a & b; } }
0.0分
5 人评分
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:658 |
A+B for Input-Output Practice (V) (C++代码)浏览:455 |
简单的a+b (C++语言代码)浏览:866 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:1352 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:599 |
生日日数 (C语言代码)浏览:1516 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:376 |
检查金币 (C语言代码)浏览:1427 |
C语言程序设计教程(第三版)课后习题6.7 (C++代码)浏览:590 |
拯救雅典娜浏览:1256 |