题目
题目

(862646) AP CS A Unit 1: Lesson 3 - Review Questions

单项选择题

Consider the following code: long y = 9223372036854775807L; y = y + 1; System.out.println(y); What number does the program print when compiled and run? Hint: think about the max value you just looked up in your previous answer.

选项
A.-9223372036854775808
B.-1
C.0
D.This program crashes and raises a longOverflow exception.
E.9223372036854775808
查看解析

查看解析

标准答案
Please login to view
思路分析
First, recall the behavior of 64-bit signed integers in Java. A long is a 64-bit two's complement integer, with a range from -2^63 to 2^63 - 1, i.e., from -9223372036854775808 to 9223372036854775807. This means that when you add 1 to the maximum value, the value wraps around to the minimum value due to overflow. Option 1: -92233720368......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!