Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,864 questions

51,786 answers

573 users

How to set a default value to function parameters in Kotlin

1 Answer

0 votes
fun main() {
	f()
	f(3)
	f(5, 3.14)
	f(19, 0.01, "Kotlin")
}

fun f(a: Int=0, b: Double=0.0, c:String="default value string") {
	println("a=$a, b=$b, c=$c")
}
  
  
   
/*
run:
 
a=0, b=0.0, c=default value string
a=3, b=0.0, c=default value string
a=5, b=3.14, c=default value string
a=19, b=0.01, c=Kotlin
 
*/

 



answered Jan 28, 2025 by avibootz

Related questions

1 answer 89 views
1 answer 72 views
1 answer 91 views
2 answers 89 views
2 answers 88 views
1 answer 90 views
1 answer 69 views
...