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

有容乃大

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'。

全部评论

相关推荐

能干的三文鱼刷了100道题:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
36
1
分享

创作者周榜

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