Skip to main content

Sum the powers 2n of all integers n between two given numbers

/** My Test Scala file**/
package main.scala

/**  * Created by Dinuka on 4/8/2017.  */object SumBetween extends App{
  print("Please insert start No :")
  val start = scala.io.StdIn.readInt()
  print("Please insert end No :")
  val end = scala.io.StdIn.readInt()

  def sum(start:Int,end:Int): Int ={
    var sumOfNums = 0    for (i <- start+1 until end){
      sumOfNums += i*i
    }
    sumOfNums
  }

  println(sum(start,end))
}
/**def sum(): Unit ={    print("Please insert start No :")    val start = scala.io.StdIn.readInt()    print("Please insert end No :")    val end = scala.io.StdIn.readInt()    var sumOfNums = 0    for (i <- start+1 until end){      sumOfNums += i*i    }    println(sumOfNums)  }
**/

Comments

Popular posts from this blog

Ubuntu 18.04 LTS (bionic beaver)

Hey! Ubuntu lovers  😊  your next buddy,  Ubuntu 18.04 LTS ( bionic beaver )  will release on next 26th of April 2018. There are many new features in this Ubundu 18.04.Okay... Let's see some new features in Ubuntu 18.04 LTS .   New Ubuntu 18.04 has GNOME 3.28   It has a better boot speed. It has a new minimal installation option. Using PPA in new Ubuntu 18.04 is slightly easy. New look in file manager. New installer for Ubuntu 18.04 Server edition. Native support for color emojes. The proposed brand new themes and icon developed by the community will no longer be the default. Default new applications. Some of the are, Video player/Music Player         VLC IDE                                             Visual Studio Code Video Editor                   ...
https://github.com/dinuka-kasun-medis

Koobiyo with Ants