Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Swift Online

import Foundation
import Glibc
    var input = "the quick brown fox jumps over the lazy dog"
    let a = "a".characters
    let e = "e".characters
    let i = "i".characters
    let o = "o".characters
    let u = "u".characters
    let consonants = "bcdfghjklmnpqrstvwxyz".characters
    var aCount = 0
    var eCount = 0
    var iCount = 0
    var oCount = 0
    var uCount = 0
    var consonantCount = 0

    for letter in input.lowercased().characters {
        if consonants.contains(letter) {
            consonantCount += 1
        } else {
            if a.contains(letter) {
                aCount += 1
            }
            if e.contains(letter) {
                eCount += 1
            }
            if i.contains(letter) {
                iCount += 1
            }
            if o.contains(letter) {
                oCount += 1
            }
            if u.contains(letter) {
                uCount += 1
            }
        }
    }
    print("A =", aCount)
    print("E =",eCount)
    print("I =",iCount)
    print("O =",oCount)
    print("U =",uCount)
    print("Consonant =",consonantCount)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.