Ghanshyam Mule
Ghanshyam Mule

Reputation: 1

Regarding shift operator

I have the following snippet but I am not sure if it is correct. Calling the function getdata() should perform some left shift operations. Could you please help me to solve this snippet: what values are going to be returned?

 private static String getdata() {
        int i = 0;
        for (int b= 0; b < 16; b++) {
              i |= b<<b
              return Integer.toString(i);
         }
 }

Upvotes: 0

Views: 39

Answers (1)

Manoj Kumar
Manoj Kumar

Reputation: 380

You can use SOP to print the output on console like the code snippet below.

    public static void main(String args[]){
        getdata();

    }

    private static void getdata() {
        int i = 0;
        for (int b= 0; b < 16; b++) {
              i |= b<<b;

              System.out.println(i+"\n");
         }
  }

OutPut is

506

1018

3066

7162

15354

31738

64506

130042

261114

523258

Upvotes: 1

Related Questions