Tech Study

Write a Swift program to move the last two characters of a given string to the start string

Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.

 

func swapletters(_ str1: String) -> String {
    var chars = str1.characters
    let last_char = chars.removeLast()
    let rest_part = chars.removeLast()
    chars.insert(last_char, at: chars.startIndex)
    chars.insert(rest_part, at: chars.startIndex)
 
    return String(chars)
}
print(swapletters("tech"))
print(swapletters("study"))

Result

Write a Swift program to move the last two characters of a given string to the start string
Write a Swift program to move the last two characters of a given string to the start string

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more