Franz:
Yes, you can use a String instead of a char array. Here's how I did it:
public static void main(String[] args) {
String foo = "Franz";
// Display string
System.out.println("Here is your original string: " + foo);
//Display start of message for palindrome
System.out.print("\nHere is the palindrome of your string: ");
//Print out letters in reverse order
for (int i = foo.length() - 1; i >= 0; i--) {
System.out.print(foo.charAt(i));
}
System.out.print("\n");
}
}
Cheers!
Eric
On Feb 22, 2009 7:06am, franzgabriel <[email protected]> wrote:
> I am curious about palindrome, how to change a word :
> Franz
> and then the word become :
> znarF
> My java code is :
> class ArrVal
> {
> public static void main (String[] args)
> {
> char value[] = {'F','r','a','n','z'};
> System.out.print("the original word :" + '\n');
> System.out.print(value[0]);
> System.out.print(value[1]);
> System.out.print(value[2]);
> System.out.print(value[3]);
> System.out.println(value[4]);
> System.out.print("the word would be :" + '\n');
> System.out.print(value[4]);
> System.out.print(value[3]);
> System.out.print(value[2]);
> System.out.print(value[1]);
> System.out.println(value[0]);
> System.out.println("Dimension array size is : " + value.length);
> }
> }
> ----------------------------------------------------------------------------------------------------
> The output program is :
> the original word :
> Franz
> the word would be :
> znarF
> Dimension array size is : 5
> ----------------------------------------------------------------------------------------------------
> My question :
> 1. Is there another way to change a word without accessing a character
> of array one by one to show it??
> 2. Is it possible create it in a String object?? how anybody give me
> java snippet please??
> somebody help me please??
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---