Multiplying long values?

前端 未结 5 993
盖世英雄少女心
盖世英雄少女心 2020-12-03 14:08
class Main {  
   public static void main (String[] args){  
     long value = 1024 * 1024 * 1024 * 80;  
     System.out.println(Long.MAX_VALUE);  
     System.out.         


        
5条回答
  •  被撕碎了的回忆
    2020-12-03 14:54

    This code:

    long value = 1024 * 1024 * 1024 * 80; 
    

    multiplies some integers together, converts it to a long and then assigns the result to a variable. The actual multiplication will be done by javac rather than when it runs.

    Since int is 32 bits, the value is wrapped and results in a zero.

    As you say, using long values in the right hand side will give a result which only wraps if it exceeds 64 bits.

提交回复
热议问题