'and' shd have been declared as char... not a String .. since name.charAt(i)
is a char .. See fixed code below:
public class Backward {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
System.out.print("Enter a Name to Reverse:");
String name = in.next();
char and;
String 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 4:10 PM, Olukosi, Olanrewaju Temitope <
[email protected]> wrote:
> 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]<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