Skip to content

can reverse any input, also has a palindrome check

Notifications You must be signed in to change notification settings

nsofiia/reverse-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

reverse-string

is a simple game, which function is to reverse all possible input from the user.

content:

  1. introduction.
  2. results.
  3. plaindrome.

introduction.

reverse_string can handle introducing itself to the player:

Screen Shot 2022-12-11 at 5 58 19 PM

Results

reverse_string is producing results right avay, after input is submitted. Results are executed by a for loop, combined with printing statement for current character. Printing is strating from the very last character.

code

for (int index = lastIndex; index > -1; index--) //starting from the last index and print each letter untill index is more than -1 { Console.Write(initialInput[index]); //displaying the reversed order character by character

Screen Shot 2022-12-11 at 5 58 41 PM

Palindrome detection

quick tip: palindrome

The reverse_string game has a hidden feature which is revealed when input is a palindrome. Detection is executed by if statement, to introduce a condition. Condition is checking whether last character is not equal to the first character, and so on, looping through input in both directions, comparing ascending order with the descending order of characters. When at least 1 pair of characters is not equal to each other - it is not a plalindorme. The isPalindrome variable is set to false. As a result - user is only getting the reversed input. Nothing else is printed. When if consition is never executed - which means that all pairs of letters from input are equal - the

Yay, found a Palindrome!

message is printed additionally for user.

code

if (initialInput[index] != initialInput[lastIndex - index]) // palindrome check - if letter from the end not equal to letter from the beginning { isPalindrome = false; //when at least 1 letter is not equal - isPalindrome switches to false }

reverse_string Palindrome detection:

Screen Shot 2022-12-11 at 6 15 51 PM

About

can reverse any input, also has a palindrome check

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages