Kotlin Program to Print an Integer

Kotlin Server Side ProgrammingProgramming

In this article, we will understand how to print an integer. Integer is a primitive data type that contains numbers up to 32 bits.

Below is a demonstration of the same −

Suppose our input is −

45

The desired output would be −

The integer is: 45

Algorithm

  • Step 1 − START

  • Step 2 − Define the integer value in a variable

  • Step 3 − Display it on the console

  • Step 4 − STOP

Example 1

In this example, we will simply print an integer using the print() method. First, declare an integer variable, which will be our input number

val inputInt = 45

Now, print the above integer using the print() method −

print("The integer is defined as: " +inputInt)

Let us now see the complete example −

fun main() { val inputInt = 45 print("The integer is defined as: " +inputInt) }

Output

The integer is defined as: 45

Example 2

Here, we have created a custom function and printed an integer −

fun printInt(inputInt : Int){ println("The integer is defined as: " +inputInt) } fun main() { val inputInt = 45 printInt(inputInt) }

Output

The integer is defined as: 45
raja
Updated on 13-Oct-2022 12:19:29

Advertisements