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

Switch

import Foundation

// 1.

var someText = "In this example, depending on whether you wanted the original total amount or the updated total amount, either $5 or $320 could be the correct answer. Before you can fix the conflicting access, you have to determine what it was intended to do."

var vowel = 0
var consonant = 0
var symbol = 0
var numeral = 0

for char in someText.lowercased() {
    switch char {
    case "a", "e", "i", "o", "u", "y":
		vowel += 1
    case "a"..."z":
        consonant += 1
    case "0"..."9":
        numeral += 1
    case ".", ",", "!", "?", "$", "%", "&", " ":
        symbol += 1
    default:
        break    
    }
}

print("vowels = \(vowel)")
print("consonants = \(consonant)")
print("symbols = \(symbol)")
print("numerals = \(numeral)")

Advertisements
Loading...

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