Handling long type argument in Scala

后端 未结 3 1455
别那么骄傲
别那么骄傲 2021-01-26 02:33
object LPrimeFactor {
  def main(arg:Array[String]):Unit = {
  start(13195)
  start(600851475143)

  }

  def start(until:Long){

    var all_prime_fac:Array[Int] = Arra         


        
相关标签:
3条回答
  • 2021-01-26 02:51

    Pass the argument as a Long (notice the L at the end of the number):

    start(600851475143L)
                   // ^
    
    0 讨论(0)
  • 2021-01-26 03:01

    Please remember literals values, if you has not any type direct suffix, the compiler try to get your numeric type values, such as 600851475143 as type Int, which is 32-bit length, two complement representation

    MIN_VALUE = -2147483648(- 2 ^ 31)  
    MAX_VALUE = 2147483647(2 ^ 31 - 1)
    

    So please add right suffix on the literal value, as 600851475143L

    0 讨论(0)
  • 2021-01-26 03:02

    To create a Long literal you must add L to the end of it.

    start(600851475143L)
    
    0 讨论(0)
提交回复
热议问题