求各个数据类型的字节大小

有容乃大

https://www.nowcoder.com/practice/4712159bbc15417086d40d6c6ff94fee?tpId=107&tqId=33284&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking

public class Main{
    public static void main(String[] args){
        System.out.println("The size of short is "+Short.SIZE/8+" bytes.");
        System.out.println("The size of int is "+Integer.SIZE/8+" bytes.");
        System.out.println("The size of long is "+Long.SIZE/8+" bytes.");
        System.out.println("The size of long long is "+Long.SIZE/8+" bytes.");
    }
}

知识点:1.求数据类型字节大小时,要使用Short.SIZE/8,Integer.SIZE/8,Long.SIZE/8,Long.SIZE/8等,原因为Short.SIZE表示的是所占空间的大小即所占位大小,而字节大小为位大小/8。
2.注意求int型字节大小为Integer,而不是Int.
3.注意各个数据类型首字母要大写,而且SIZE要大写。
4.使用System.out.println()时,会自动在末尾加上'\n'。

全部评论

相关推荐

Lorn的意义:1.你这根本就不会写简历呀,了解太少了 2.你这些项目经历感觉真的没啥亮点啊,描述的不行,重写书写一下让人看到核心,就继续海投 注意七八月份ofer还是比较多的,越往后机会越少,抓住时机,抓紧检查疏漏,加油查看图片
点赞 评论 收藏
分享
评论
36
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务