File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ public class PalindromicNumber
3+ {
4+ public static void Main ( string [ ] args )
5+ {
6+
7+ try
8+ {
9+ long verifyInput = long . Parse ( args [ 0 ] ) ;
10+
11+ if ( verifyInput >= 0 )
12+ {
13+ Console . WriteLine ( palindrome ( args [ 0 ] ) ) ;
14+ }
15+ else
16+ {
17+ Console . WriteLine ( "Usage: please input a non-negative integer" ) ;
18+ }
19+
20+ }
21+ catch
22+ {
23+ Console . WriteLine ( "Usage: please input a non-negative integer" ) ;
24+ }
25+
26+ }
27+
28+ public static string palindrome ( string numString )
29+ {
30+ char [ ] digits = numString . ToCharArray ( ) ;
31+
32+ int backCount = digits . Length - 1 ;
33+
34+ for ( int i = 0 ; i < digits . Length ; i ++ )
35+ {
36+ if ( digits [ i ] != digits [ backCount ] )
37+ {
38+ return "false" ;
39+ }
40+ else
41+ {
42+ backCount -- ;
43+ }
44+
45+ }
46+
47+ return "true" ;
48+
49+ }
50+
51+ }
You can’t perform that action at this time.
0 commit comments