Sunday 15 February 2015

What is the output of the following Java Program-1



Program:

import java.io.*;
public class test
{
           public static void main(String args[])
           {
                      System.out.println(7|8);
           }
}

Options:

a) 7
b) 8
c) 15
d) error

Explanation:

Option: c) is correct.

Here we can do the OR( | ) operation for 7 and 8.

The Binary value of 7 is  0111
The Binary value of 8 is 1000

      7 --->  0111
      8 --->  1000
----------------------
                 1111 
----------------------

The Decimal value of 1111 is 15.

So answer is 15.




Thanks for visiting.......

0 comments:

Post a Comment