From 51fd45dfeabf6c81a45f45d2e2ff0fc06f8c12da Mon Sep 17 00:00:00 2001 From: LatteCosmos Date: Sat, 20 Dec 2025 08:35:13 +1100 Subject: [PATCH] use long type instead of integer type to fix the overflow issue --- src/main/java/com/github/hcsp/datatype/IntegerOverflow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/hcsp/datatype/IntegerOverflow.java b/src/main/java/com/github/hcsp/datatype/IntegerOverflow.java index e476132..c1cd9bd 100644 --- a/src/main/java/com/github/hcsp/datatype/IntegerOverflow.java +++ b/src/main/java/com/github/hcsp/datatype/IntegerOverflow.java @@ -4,8 +4,8 @@ public class IntegerOverflow { // 修复这个方法里的问题,使得它正确输出 "i=3000000000" // Fix this method to make it output "i=3000000000" public static void main(String[] args) { - int 十亿 = 10_0000_0000; - int i = 0; + long 十亿 = 10_0000_0000; + long i = 0; i = i + 十亿; System.out.println("i=" + i);