package com.example;

import java.util.Scanner;

public class Backward {
            public static void main (String[] Args)
            {
                Scanner in=new Scanner(System.in);
                System.out.print("Enter a Name to Reverse:");
                String name = in.nextLine();
                char and;
                String out="";
                int l=name.length();
                int i;
                for (i=l-1; i>=0; i--)
                {
                    and=name.charAt(i);
                    System.out.println(and);
                    out=out+and;
                }
                System.out.println("The Output is:" + out);
            }
}


This code is compile fine and run successfully .

On 9/2/10, Gagan Arora <[email protected]> wrote:
> I think that Mihai has pointed out the logical problem in your code but
> there are other conventions that you are not following which should be
> discouraged ... I have marked them as red. Classes should start with capital
> letter and variables should start with lowercase vars. I also recommend
> downloading CheckStyle for you IDE.
>
> http://en.wikipedia.org/wiki/Naming_convention_(programming)
>
> Thanks,
> G
>
> import java.util.Scanner;
> class backward
> {
>     public static void main (String[] Args)
>     {
>         Scanner in=new Scanner(System.in);
>         System.out.print("Enter a Name to Reverse:");
>         String name = in.nextLine();
>         String and, ans;
>         int l=name.length();
>         int i;
>         for (i=l-1; i>=0; i--)
>         {
>             and=name.charAt(i);
>             ans= ans+and;
>         }
>         System.out.println("The Output is:" + ans);
>     }
> }
>
>
>
>
>
> On Wed, Sep 1, 2010 at 1:47 PM, Mihai DINCA <[email protected]> wrote:
>
>>  Hi
>>
>> You say "String and, ans;", then, later, "and = name.charAt(i);".
>>
>> As the error message says, the method "charAt(...)" returns a value of
>> type
>> "char", while your variable "and" is of type "String".
>>
>> There are many ways to make your code working, but the simplest way is to
>> replace the line of code:
>>     ...
>>     String and, ans;
>>     ...
>> by two lines:
>>     ...
>>     String ans;
>>     *char and;*
>>     ...
>>
>> The line of code "ans = ans + and;" will still work after this
>> modification, as the "+" operator allows to append a char (or any other
>> simple type) to a String (this is what allows you to write "for(int i = 0;
>> i < 10; i++) System.out.println(*"Iteration # " + i*);").
>>
>> Hope it helps
>> Mihai
>>
>>
>> Le 01/09/2010 22:10, Olukosi, Olanrewaju Temitope a écrit :
>>
>> Hello Guys,
>>
>> I am having some problems running this program. Kindly help
>>
>> import java.util.Scanner;
>> class backward
>> {
>>     public static void main (String[] Args)
>>     {
>>         Scanner in=new Scanner(System.in);
>>         System.out.print("Enter a Name to Reverse:");
>>         String name = in.nextLine();
>>         String and, ans;
>>         int l=name.length();
>>         int i;
>>         for (i=l-1; i>=0; i--)
>>         {
>>             and=name.charAt(i);
>>             ans= ans+and;
>>         }
>>         System.out.println("The Output is:" + ans);
>>     }
>> }
>>
>>
>> The error I have is stated thus using TextPad
>>
>> C:\JavaClass\backward.java:14: incompatible types
>> found   : char
>> required: java.lang.String
>>             and=name.charAt(i);
>>                            ^
>> 1 error
>>
>> Tool completed with exit code 1
>>
>> --
>> DISCLAIMER
>> This message contains privileged and confidential information and is
>> intended only for the individual named. If you are not the intended
>> recipient you should not disseminate, distribute, store, print, copy or
>> deliver this message. Please notify the sender immediately by e-mail if
>> you
>> have received this e-mail by mistake and delete this e-mail and any
>> attachments from your system. E-mail transmission cannot be guaranteed to
>> be
>> secure or error-free as information could be intercepted, corrupted, lost,
>> destroyed, arrive late or incomplete or contain viruses. The sender
>> therefore does not accept liability for any errors or omissions in the
>> contents of this message which arise as a result of e-mail transmission.
>> Thank you   --   Tope Olukosi
>> --
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>>
>>  --
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<javaprogrammingwithpassion%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>>
>
> --
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en


-- 
Thanks And Venerate
Prateek Kumar Shaw
Java Programmer
Al-Naghi Company
Jeddah

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to