Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question~! need help with my codes

 
Franky Massenger
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I just started learning Java ,and I'm working on a drill in the Java-self teaching book.
But I can't get it work.
Please tell me what the problem is and teach me a little bit.
Thank you

Here is problem that's been a huge pain in my butt. :

As a young boy Franklin Roosevelt signed his letters to his mother backwards: Tlevesoor Nilknarf. Write a program that accepts a person's name and print it backwards. Make sure that you have the appropriate capital letters.


And here goes my codes:

public class backwad
{
public static void main (String [] args)
{
String first = "Tlevesoor";
String last = "Nilknarf";
String firstN = "";
String lastN = "";
for (int i = first.lenth()-1; i <= 0; i--)
{
char c1 = first.charAt(i);
firstN += c1;
{
char b1 = firstN.charAT(0);
String a1 = firstN.substring(1,8);
firstN = character.toUpperCase(b1) + a1;
for (int i = last.lenth()-1; i <= 0; i--)
{
char c2 = last.charAt(i);
lastN += c2;
}
char b2 = lastN.charAT(0);
String a2 = firstN.substring(1,7);
lastN = character.toUpperCase(b2) + a2;

System.out.print(lastN = " ");
System.out.print(firstN);
}

}
[ October 22, 2004: Message edited by: Franky Massenger ]
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is homework time already? Why don't you tell us what you understand about the code, and we'll tell you if we agree.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about making life easier?

String -> an array -> reverse array -> String
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two hints that will allow this code to compile: One of your braces is backwards, and Java identifiers are case sensitive.

(Then be prepared for Runtime Exceptions...)
 
Ashutosh Gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seems to be lote of typo errors. Simply, retryping from the book, taking case sensitiveness into care will do
 
Franky Massenger
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for giving me hints. But can you guys pinpoint the part where
the errors seem to be, and fix it for me? I read through two books and I still can't firgure out what the problem is. Or Could you try to write your own codes so I can get some ideas how to compose codes. Thank you
 
rahul V kumar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try compiling your java code? If so what compile errors did you get. You should be able to identify whats wrong in your code based on compile errors.

Check for the following in your code and fix it & make sure it compiles.

1) Check for the for loop braces. One of the for loop's closing braces are wrong.
2) Strings do not have lenth() & CharAT() function. What are the correct ones?

Hope this helps
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you correct that reversed brace at the end of your first "for" loop, the compiler errors will pinpoint the other syntax issues for you (the misspellings and incorrect case).

Address these one by one so you know you're headed in the right direction: Compile, fix one of the errors, compile again and you should have one less error. Compile, fix one of the errors, compile again...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic