By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

C#...Writing a progrm that reverse the string name you enter...

P: 19
Hello every one:
I have to write a program that reverse and displays the charactors of a pharase typed from the keyboard.
This is what I wrote:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. public class YourName
  3. {
  4.     public static void Main(string[] args)
  5.     {
  6.         Console.WriteLine("Enter a word");
  7.         string word = Console.ReadLine();
  8.         for (int i; i >0; i--)
  9.         {
  10.             Console.Write(word[i]);
  11.         }
  12.     }
  13. }
  14.  
Please let me know what is wrong with the code I wrote.
Can you please re-write the code.
Thanks
Jan 24 '09 #1
Share this Question
Share on Google+
2 Replies


P: 19
I figure it out.All i needed to do was finding the length of the string and use in in the loop,
Jan 24 '09 #2

Expert 100+
P: 190
Yes, but you will still have a small error even after you get the string length.
Since this is a learning assignment, you should try hard to figure it out by yourself - you will learn better that way.
Hint: C# arrays start at (and include) index '0';

Good luck.
Jan 25 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.