Write a Dart program to create a new string from a given string where the first and last characters will change their positions.

Test Data:
Python

Sample Output:
nythoP

Code:

import 'dart:io';

void main() {
  stdout.write('Input word : ');
  String word = stdin.readLineSync();
  String result;

  result = word[word.length - 1] + word.substring(1, word.length - 1) + word[0];
  print(result);
}

Output:

Comments

Popular posts from this blog

Write a Dart program to convert from celsius degrees to Kelvin and Fahrenheit.

Write a Dart program to create a new string from a given string (length 1 or more ) with the first character added at the front and back.