小编Den*_*nis的帖子

bitParity - 查找整数中的奇数位数

我必须创建一个bitParity(int x)取整数的函数,1如果0在位形式中有奇数个,则返回x,0否则返回.

例如: bitParity(5) = 0, bitParity(7) = 1

但是,这很难,因为我只能在这个问题上使用位运算符(! ˜ & ˆ | + << >>是唯一合法的).这意味着,没有循环,if-then或任何类型的东西.可以使用常量.

到目前为止,我有什么不行的,但我想,我应该整数的位移位16,8以及4时间和XOR剩余的整数.

有人可以提供一些建议吗?谢谢.

c logic integer bits

2
推荐指数
2
解决办法
1万
查看次数

"无法在Java中找到符号 - 方法hasNextLine()"错误

我正在尝试编写一个使用文件I/O进行个性测试评分的程序.但是,当我得到这个代码时:

while (f.hasNextLine()) {
Run Code Online (Sandbox Code Playgroud)

我收到标题中描述的错误.这是完整的代码.我之前导入了所有必要的I/O和实用程序,我认为我正确地声明了文件变量.我知道这种方法存在,但问题是什么?

import java.io.*;
import java.util.*;
public class PersonalityTest {
    public static Scanner input = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        String input = input();
        String output = output();
        results(input, output);
        System.out.println("Your results are located in the file you requested.");
    }

    public static String input() throws IOException {
        System.out.print("Input file name: ");
        String file = input.nextLine();
        File f = new File(file);
        System.out.println();

        while (!f.exists()) {
            System.out.print("File not found. Try again: ");
            file = …
Run Code Online (Sandbox Code Playgroud)

java methods file-io

1
推荐指数
1
解决办法
6584
查看次数

标签 统计

bits ×1

c ×1

file-io ×1

integer ×1

java ×1

logic ×1

methods ×1