int类型数字特别大
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                int类型数字特别大
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                package com.company;
public class Demo06 {
 ? ? public static void main(String[] args) {
 ? ? ? ? //操作比較大數時注意溢出問題
 ? ? ? ? //JDK7新特性,數字之間可以用下劃線分隔
 ? ? ? ? int money=10_0000_0000;
 ? ? ? ? System.out.println(money);
 ? ? ? ? int years=20;
 ? ? ? ? int total=money*years;
 ? ? ? ? System.out.println(total);//-1474836480計算時溢出了
 ? ? ? ? long total2=money*years;
 ? ? ? ? System.out.println(total2);//-1474836480默認是int,轉換之前已經存在問題了
 ? ? ? ? long total3=money*((long)years);//先把一個數轉換為long
 ? ? ? ? System.out.println(total3);//20000000000正確
 ? ? }
 }
 1000000000
 -1474836480
 -1474836480
 20000000000
加qq群422464063學習
總結
以上是生活随笔為你收集整理的int类型数字特别大的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Python int函数 - Pytho
- 下一篇: java设计模式-简单工厂模式
