Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Total points: 100
- You must work on this assignment ALONE. It is split into two parts. Submit them separately following the instructions for each part.
- Part 1 (50 points)
- a. (40 points) What is the output of the following Java program? You must type your answer on
- a separate sheet with your name on it. For full credit, match the program’s output EXACTLY,
- including white space, newline characters, upper/lowercase characters, vertical alignment, etc.
- Important advice: To better prepare for quizzes and exams, solve this problem on paper, without
- typing, compiling and running the Java program. Recall that Java uses 32-bit integers.
- class Logical
- {
- static String hex(int x)
- {
- return Integer.toHexString(x).toUpperCase();
- }// hex method
- static void print_values(int x)
- {
- System.out.format("x = %d (base 10) = 0x%s\n", x, hex(x));
- System.out.format("Line 1: %6s = %11d (dec.) = 0x%s\n",
- "x<<1" , x<<1 , hex(x<<1));
- System.out.format("Line 2: %6s = %11d (dec.) = 0x%s\n",
- "x<<2" , x<<2 , hex(x<<2));
- System.out.format("Line 3: %6s = %11d (dec.) = 0x%s\n",
- "x<<31", x<<31, hex(x<<31));
- System.out.println();
- System.out.format("Line 4: %6s = %11d (dec.) = 0x%s\n",
- "x>>1" , x>>1 , hex(x>>1));
- System.out.format("Line 5: %6s = %11d (dec.) = 0x%s\n",
- "x>>2" , x>>2 , hex(x>>2));
- System.out.format("Line 6: %6s = %11d (dec.) = 0x%s\n",
- "x>>31", x>>31, hex(x>>31));
- System.out.println();
- System.out.format("Line 7: %6s = %11d (dec.) = 0x%s\n",
- "x>>>1", x>>>1 , hex(x>>>1));
- System.out.format("Line 8: %6s = %11d (dec.) = 0x%s\n",
- "x>>>2", x>>>2 , hex(x>>>2));
- System.out.format("Line 9: %6s = %11d (dec.) = 0x%s\n",
- "x>>>31", x>>>31, hex(x>>>31));
- System.out.println("\n");
- }// print_values method
- public static void main(String[] args)
- {
- print_values( 14 );
- print_values( -14 );
- }// main method
- }// Logical class
Add Comment
Please, Sign In to add comment