参考代码:
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语言代码)浏览:684 |
字符串对比 (C语言代码)浏览:1426 |
三角形 (C++代码)递推浏览:771 |
Hello, world! (C++代码)浏览:1747 |
1017题解浏览:608 |
循环入门练习5 (C语言代码)浏览:859 |
【偶数求和】 (C语言代码)浏览:439 |
剪刀石头布 (C++代码)浏览:1729 |
Tom数 (C语言代码)浏览:561 |
GC的苦恼 (C语言代码)浏览:633 |