Skip to main content

 

Kotlin Function

function means use big problems divided by submodule and easily problems solved. It makes reusability of code and makes the program more manageable

There are two types of functions:
  1. Standard library function
  2. User-defined function

Standard Library Function

Kotlin Standard library function is built-in library functions
import java.time.LocalDateTime

fun main(args: Array<String>) {

    val current = LocalDateTime.now()

    println("Current Date and Time is: $current")
}

User-defined Function

A user-defined is created by the user. User-defined function takes the parameter(s), perform an action and return the result of that action as a value.

  1. fun main(args: Array<String>){  
  2.     sum()  
  3.     print("code after sum")  
  4. }  
  5. fun sum(){  
  6.     var num1 =5  
  7.     var num2 = 6  
  8.     println("sum = "+(num1+num2))  
  9. }  

paremetarize function : 

  1. fun main(args: Array<String>){  
  2.    val result = sum(56)  
  3.     print(result)  
  4. }  
  5. fun sum(number1: Int, number2:Int): Int{  
  6.     val add = number1+number2  
  7.     return add  
  8. }  





Comments

Popular posts from this blog

 var val  deference in kotlin  fun main () { var Android_Programing_language : String = "java" println ( "android official programing language: " + Android_Programing_language ) Android_Programing_language = "Kotline" println ( "2019 google announced android official programing language: " + Android_Programing_language ) val Android_MultiPlatform_language : String = "Dart" println ( "multiple device run : " + Android_MultiPlatform_language ) /* Android_MultiPlatform_language="" /* note: var--------------valu changable note: val--------------valu not changable (final) */ */ }
 Firebase Cloud Messaging With  push notification with Image  public class ImageDownload extends AsyncTask < String , Void , Bitmap >{ @Override protected Bitmap doInBackground ( String ... strings ) { InputStream inputStream ; try { URL url = new URL( strings [ 0 ]) ; try { HttpURLConnection connection = ( HttpURLConnection ) url .openConnection() ; connection .connect() ; inputStream = connection .getInputStream() ; return BitmapFactory . decodeStream ( inputStream ) ; } catch ( IOException e ) { e .printStackTrace() ; } } catch ( MalformedURLException e ) { e .printStackTrace() ; } return null; } @Override protected void onPostExecute ( Bitmap bitmap ) { ShowNotification( bitmap ) ; } }
AppBar ViewPager with  Tab layout in android  XML : <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" xmlns: app ="http://schemas.android.com/apk/res-auto" android :id ="@+id/mainrelative_layout_id" android :background ="@color/colorPrimary" android :theme ="@style/Appthemnoactionbar" android :layout_height ="match_parent" tools :context ="com.ruhul.scanner.Fragment_Activity.ListFragment" > <com.google.android.material.appbar.AppBarLayout android :id ="@+id/tablayoutid" android :layout_width ="match_parent" android :background ="@color/colorPrimary" android :layout_height ="?actionBarSize" > ...