Get a string in which the characters of the string "stressed" are arranged in reverse (from the end to the beginning).
Go
package main
import_ "fmt"
func main() {
var data string = "stressed"
var reverse string
// 1.loop
for i := len(data) - 1; i >= 0; i-- {
reverse += string(data[i])
}
fmt.Println(reverse)
}
python
# -*- coding: utf-8 -*-
data = "stressed"
reverse = ""
# 1.Reverse count loop
i = len(data) - 1
while i >= 0:
reverse += data[i]
i-=1
print(reverse)
# 2.range->reversed
reverse = ""
for i in reversed(range(len(data))):
reverse += data[i]
print(reverse)
# 3.reversed->join
print(''.join(reversed(data)))
# 4.slice
print(data[::-1])
Javascript
var data = "stressed";
var reverse = ""
// 1.Reverse count loop
for (var i = data.length - 1; i >= 0; i--) {
reverse += data[i];
}
console.log(reverse);
// 2.split->reverse->join
console.debug(data.split("").reverse().join(""));
go does not support Japanese. Problem page and top page split.
Recommended Posts