Sollicitatievraag bij Amazon

Reverse a string

Antwoorden op sollicitatievragen

Anoniem

12 sep 2018

def main(): str=input("Enter a string") print(str[: : -1]) main()

2

Anoniem

21 jul 2018

Javascript const foo = "bar"; const baz = foo.split('').reverse().join(''); :^)

1

Anoniem

8 feb 2020

How about this: for(int index = 0; index < input.length() ; index++ ) { output.insert(0, input.charAt(index)); }

Anoniem

13 mei 2016

String n='he' for (int i=n.length-1; i--;i>=0){ String n_rev = n.CharAt(i)+n; } System.out.println(n_rev);

Anoniem

16 apr 2017

// Converted the String into Char array char[] a = str.toCharArray(); // create a new String StringBuilder sb = new StringBuilder(); // Started a loop for (int i = a.length - 1; i >= 0; i--) { // Add character sb.append(a[i]); } // Print out the string System.out.println(sb);

Anoniem

15 mei 2017

Ruby : a = "This test is simple".downcase b = a.chars.to_a temp = [] len = b.length for i in 1...len+1 temp.push(b[-i]) end f = temp.join print f Output: elpmis si tset siht

Anoniem

28 apr 2014

Using Python : def reverse(string): L = [] count = 1 for i in range(0,len(string)): L.append(string[len(string)-count]) count += 1 L_reverse = ''.join(L) return L_reverse

Anoniem

1 okt 2018

# Python: def reverse_str(s): return s[::-1]

Anoniem

4 mei 2014

public String reverseMe(String string1) { int length = string1.length(); char[] charArray = new char[length]; int j = 0; for(int i = length -1 ; i >= 0 ; i--) { charArray[j++] = string1.charAt(i); } String string2 = new String(charArray); return string2; }