Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/trivial_demonstrations/palindrome.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::io;
fn main(){
//here we take input
let mut num=String::new();
io::stdin().read_line(&mut num).expect("");
//here we use len() to find length of string
let half_len = num.len()/2;
// here we use take() for taking a substring and eq for comparing
//here we check palindrome
if num.chars().take(half_len).eq(num.chars().rev().take(half_len))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition always yields false. Please run and test the program before creating pull request.

trim the whitespaces from num before taking half_len. Rust donot remove whitespaces by default.

use num.trim() to remove whitespaces.

{println!("it is palindrome");}
else
{ println!("it is not palindrome");}
}