- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print 0001 to 1000 in Kotlin with padding
In this example, we will see how to print 0001 to 1000 in Kotlin with padding. For this purpose, we will use a Kotlin library function called padStart().
padStart is a function which returns a charSequence. Its function definition looks like this −
fun CharSequence.padStart( length: Int, padChar: Char = ' ' ): CharSequence
Example – Print 0001 to 1000 with padding
The following code prints 1 to 1000 with padding.
fun main(args: Array<String>) { (1..1000).forEach{println("$it".padStart(4, '0'))} }
Output
On execution, it will print a sequence of 4-digit numbers starting from 0001 to 1000.
0001 0002 0003 0004 ... ... ... 0996 0997 0998 0999 1000
- Related Articles
- Print number with commas as 1000 separators in Python
- Print number with commas as 1000 separators in C#
- Kotlin Program to Print an Integer
- Kotlin Program to Print a String
- Kotlin Program to Print the ASCII values
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- How to convert an integer to string with padding zero in C#?
- How to set the padding of an element with JavaScript?
- Padding a string with random lowercase alphabets to fill length in JavaScript
- How to work with Maps in Kotlin?
- How to set the bottom padding of an element with JavaScript?
- How to set the left padding of an element with JavaScript?
- How to set the top padding of an element with JavaScript?
- How to set the right padding of an element with JavaScript?
- Change the padding of a button with CSS

Advertisements