给定一个正整数 A (1 <= A <= 100),输出 A 的最低位.
例如,给定 A = 26,我们可以将二进制形式的 A 写为 11010,因此 A 的最低位为 10,因此输出应为 2。
另一个例子是这样的:假设 A = 88,我们可以将二进制形式的 A 写为 1011000,因此 A 的最低位为 1000,因此输出应为 8。
例如,给定 A = 26,我们可以将二进制形式的 A 写为 11010,因此 A 的最低位为 10,因此输出应为 2。
另一个例子是这样的:假设 A = 88,我们可以将二进制形式的 A 写为 1011000,因此 A 的最低位为 1000,因此输出应为 8。
每行输入仅包含一个整数 A (1 <= A <= 100)。包含“0”的行表示输入的结束,此行不是输入数据的一部分。
对于输入中的每个 A,输出一行仅包含其最低位。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n=sc.nextInt();
if(n==0) return;
String s=Integer.toString(n,2);
System.out.println(Integer.parseInt(s.substring(s.lastIndexOf('1')), 2));
}
}
}