Home>

While solving the At coder problem, I came across a code I had never seen. I looked it up on the net, but I asked a question because it didn't hit easily.
This is a rudimentary question, but thank you.

Corresponding source code
import java.util.Scanner;
public class Main {
    public static void main (String [] args) {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt ();
        int bit = 0;
        for (int i = 0;i<n;i ++) {
            bit | = sc.nextInt ();// I'm curious about | = here
        }
        System.out.println (Integer.numberOfTrailingZeros (bit));
    }
}
Supplementary information (FW/tool version, etc.)

I was solving this problem with Atcoder.

  • Answer # 1

    Search by [java | =]

    Assignment operator
    | = a | = b a = a | same as b

    It was a hit right away.

  • Answer # 2

    It is a compound assignment operator.
    x + = 4I think that you often see such things.

    And the pipe is a bit operator.

    So, if you know the two, you can understand what you are doing.

  • Answer # 3

    Pipe equal operator

    Easy-to-understand explanation

  • Answer # 4

    Search for "Java operator list".