lazine.blogg.se

Kotlin int range
Kotlin int range




kotlin int range

Here we have written a program to print numbers from 0 to 7 as follows.

kotlin int range

RangeTo method is used to print the values from the start value to end value in increasing order.

kotlin int range

As we want to print numbers from 1 to 9 and until the method excludes the last element we have defined the start value as 1 and the end value as 10 Use of rangeTo method Here we have written a program to print the numbers from 1 to 9 using until method. Program to print numbers from 1 to 9 using until method It iterates range from the start value to 1 less than the end. Until a method is used to print the values within a specific range excluding the last element. Program to print alphabets from k to a using downTo method Program to print numbers from 10 to 1 using downTo method To solve the above problem downTo() method is used to print the number or alphabets in a reversed manner. If we try to do this, it will runs the program but will not print anything.Īs the start value is greater than the end value, the output will not print anythingĪs the start value is greater than the end value, the output will not print anything Use of downTo methodĪs we can see in example 3, there is nothing in output. In the below examples, we have tried to print the number and alphabets in a reversed manner using the same method as we have used in examples 1 and 2, but the same concept doesn’t work as the start value must be small than the end value. There are some cases where we want to print numbers or alphabets in a reversed manner. Here we have used x variable to store the alphabets, as we want to print the alphabet from a to k, we have defined start value as a and end value ask. Here we have written a program to print the alphabets from a to k using range Here we have used x variable to store the number, as we want to print the number from 1 to 10, we have defined the start value as 1 and the end value as 10.






Kotlin int range