参考代码:
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 人评分
A+B for Input-Output Practice (C语言代码)浏览:458 |
数字游戏 (C++代码)浏览:1178 |
输入输出格式练习 (C语言代码)浏览:842 |
判定字符位置 (C语言代码)浏览:792 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:484 |
C语言训练-8除不尽的数 (C语言代码)浏览:1396 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:403 |
C语言程序设计教程(第三版)课后习题4.9 (Java代码)浏览:602 |
成绩转换 (C语言代码)浏览:586 |
母牛的故事 (C语言代码)浏览:757 |