Q:

Kotlin program to convert string to character array

belongs to collection: Kotlin Array Programs

0

Given a string, we have to convert it into a character array.

Example:

    Input:
    string = "IncludeHelp India Pvt Ltd"

    Output:
    char_arr = [I, n, c, l, u, d, e, H, e, l, p,  , I, n, d, i, a,  , P, v, t,  , L, t, d]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to convert string to character array in Kotlin

package com.includehelp

import java.util.*

//Main Function, entry Point of Program
fun main(args: Array<String>) {
    // InputStream to get Input
    val scanner = Scanner(System.`in`)

    //Input String
    print("Enter String : ")
    var str = scanner.nextLine()

    //convert String to Character Array
    val charArray = str.toCharArray()

    //Print Character Array get from String
    println("Character Array Elements  : ${charArray.contentToString()} ")
}
Run 1:
-----
Enter String : IncludeHelp India Pvt Ltd
Character Array Elements  : [I, n, c, l, u, d, e, H, e, l, p,  , I, n, d, i, a,  , P, v, t,  , L, t, d]
--------
Run 2:
----
Enter String : Corona Virus Covid-19 Panidimic
Character Array Elements  : [C, o, r, o, n, a,  , V, i, r, u, s,  , C, o, v, i, d, -, 1, 9,  , P, a, n, i, d, i, m, i, c]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin program to find sum and average of array el... >>
<< Kotlin program to convert character array to strin...