开发者社区> 问答> 正文

如何格式化输出,使其呈列表或网格之类的格式?

我有此输出,就像您看到的一样,由于左侧的数字增加,另一侧的整个字符串也随之移动。我该怎么办?我不太了解format类,当我查找它时,对我来说毫无意义!您能帮我,看起来很棒吗?我接受多种选择,并且我会选择外观最好和功能最好的:=)

生成数字的代码:

BigInteger number = new BigInteger("2");
    BigInteger sum;
    BigDecimal weight;
    BigDecimal finalweight;
    for(int i = 1; i <= 64; i++){
    sum = number.pow(i).subtract(new BigInteger("1"));
    weight = new BigDecimal(sum.multiply(new BigInteger("25")),9);
    System.out.print("Sum after spot " + i + ": " + sum);
    System.out.println(" weight in kg: " + weight);
    try{Thread.sleep(500);}
    catch(Exception e){System.out.println("Error");};
    }

Output:
Sum after spot 1: 1 weight in kg: 2.5E-8
Sum after spot 2: 3 weight in kg: 7.5E-8
Sum after spot 3: 7 weight in kg: 1.75E-7
Sum after spot 4: 15 weight in kg: 3.75E-7
Sum after spot 5: 31 weight in kg: 7.75E-7
Sum after spot 6: 63 weight in kg: 0.000001575
Sum after spot 7: 127 weight in kg: 0.000003175
Sum after spot 8: 255 weight in kg: 0.000006375
Sum after spot 9: 511 weight in kg: 0.000012775
Sum after spot 10: 1023 weight in kg: 0.000025575
Sum after spot 11: 2047 weight in kg: 0.000051175
Sum after spot 12: 4095 weight in kg: 0.000102375
Sum after spot 13: 8191 weight in kg: 0.000204775
Sum after spot 14: 16383 weight in kg: 0.000409575
Sum after spot 15: 32767 weight in kg: 0.000819175
Sum after spot 16: 65535 weight in kg: 0.001638375
Sum after spot 17: 131071 weight in kg: 0.003276775
Sum after spot 18: 262143 weight in kg: 0.006553575
Sum after spot 19: 524287 weight in kg: 0.013107175
Sum after spot 20: 1048575 weight in kg: 0.026214375
Sum after spot 21: 2097151 weight in kg: 0.052428775
Sum after spot 22: 4194303 weight in kg: 0.104857575
Sum after spot 23: 8388607 weight in kg: 0.209715175
Sum after spot 24: 16777215 weight in kg: 0.419430375
Sum after spot 25: 33554431 weight in kg: 0.838860775
Sum after spot 26: 67108863 weight in kg: 1.677721575
Sum after spot 27: 134217727 weight in kg: 3.355443175
Sum after spot 28: 268435455 weight in kg: 6.710886375
Sum after spot 29: 536870911 weight in kg: 13.421772775
Sum after spot 30: 1073741823 weight in kg: 26.843545575
Sum after spot 31: 2147483647 weight in kg: 53.687091175
Sum after spot 32: 4294967295 weight in kg: 107.374182375
Sum after spot 33: 8589934591 weight in kg: 214.748364775
Sum after spot 34: 17179869183 weight in kg: 429.496729575
Sum after spot 35: 34359738367 weight in kg: 858.993459175
Sum after spot 36: 68719476735 weight in kg: 1717.986918375
Sum after spot 37: 137438953471 weight in kg: 3435.973836775
Sum after spot 38: 274877906943 weight in kg: 6871.947673575
Sum after spot 39: 549755813887 weight in kg: 13743.895347175
Sum after spot 40: 1099511627775 weight in kg: 27487.790694375
Sum after spot 41: 2199023255551 weight in kg: 54975.581388775
Sum after spot 42: 4398046511103 weight in kg: 109951.162777575
Sum after spot 43: 8796093022207 weight in kg: 219902.325555175
Sum after spot 44: 17592186044415 weight in kg: 439804.651110375
Sum after spot 45: 35184372088831 weight in kg: 879609.302220775
Sum after spot 46: 70368744177663 weight in kg: 1759218.604441575
Sum after spot 47: 140737488355327 weight in kg: 3518437.208883175
Sum after spot 48: 281474976710655 weight in kg: 7036874.417766375
Sum after spot 49: 562949953421311 weight in kg: 14073748.835532775
Sum after spot 50: 1125899906842623 weight in kg: 28147497.671065575
Sum after spot 51: 2251799813685247 weight in kg: 56294995.342131175
Sum after spot 52: 4503599627370495 weight in kg: 112589990.684262375
Sum after spot 53: 9007199254740991 weight in kg: 225179981.368524775
Sum after spot 54: 18014398509481983 weight in kg: 450359962.737049575
Sum after spot 55: 36028797018963967 weight in kg: 900719925.474099175
Sum after spot 56: 72057594037927935 weight in kg: 1801439850.948198375
Sum after spot 57: 144115188075855871 weight in kg: 3602879701.896396775
Sum after spot 58: 288230376151711743 weight in kg: 7205759403.792793575
Sum after spot 59: 576460752303423487 weight in kg: 14411518807.585587175
Sum after spot 60: 1152921504606846975 weight in kg: 28823037615.171174375
Sum after spot 61: 2305843009213693951 weight in kg: 57646075230.342348775
Sum after spot 62: 4611686018427387903 weight in kg: 115292150460.684697575
Sum after spot 63: 9223372036854775807 weight in kg: 230584300921.369395175
Sum after spot 64: 18446744073709551615 weight in kg: 461168601842.738790375

这样您就可以看到我的问题了吗?

展开
收起
垚tutu 2019-12-12 09:52:26 679 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
重新定义计算的边界 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载