参考代码:
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语言程序设计教程(第三版)课后习题6.3 (Java代码)浏览:659 |
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
哥德巴赫曾猜测 (C语言代码)浏览:1021 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:564 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1119 |
【蟠桃记】 (C语言代码)浏览:1037 |
1113题解浏览:791 |
1013题解浏览:561 |
星期判断机 (C语言代码)浏览:859 |
C二级辅导-温度转换 (C语言代码)浏览:733 |