Skip to main content

Posts

Showing posts from April, 2017

Sinhala and Tamil New Year!

Scala code for nCr

package main.scala /** * Created by Dinuka on 4/8/2017. */ object nCr extends App{ print ( "Please input n value :" ) val n = scala.io.StdIn.readInt() print ( "Please input r value :" ) val r = scala.io.StdIn.readInt() def factorial(n: Int):Int = { if (n == 0 ) 1 else n * factorial (n- 1 ) } var answer = factorial ( n )/( factorial ( n - r )* factorial ( r )) println ( "Answer of " + n + "C" + r + " = " + answer ) }

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) } **/

NIC birthday checker Using Scala

package main.scala import scala.util.control._ /** * Created by Dinuka on 4/8/2017. */ object Nic extends App{ print ( "Please input your NIC :" ) var nicNo = scala.io.StdIn.readLine() val year = nicNo .substring( 0 , 2 ).toInt+ 1900 var monthdates = Array ( 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ) var dayNo = nicNo .substring( 2 , 5 ).toInt var gender = "Male" if ( dayNo > 500 ){ dayNo -= 500 gender = "Female" } def setMonth(day1:Int): String ={ var month ,da = 0 var day=day1 var i= 0 val loop = new Breaks; loop.breakable { for (i<- 0 until monthdates .length- 1 ){ if (day < monthdates (i)){ month=i+ 1 da=day loop.break } else { day =day- monthdates (i) } } } ( " \n Month : " + month + " \n Date : " + da+ " \n " ); } println ( "Year :" + y...