943,428 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5828
  • Java RSS
Oct 14th, 2004
0

need help to create a java program

Expand Post »
hi all,
i am a beginner in java programming.Could anyone please provide source code for the following program.
A program that reads a integer and breaks it into a sequence of individual digits in reverse order.TQ.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kumar25 is offline Offline
1 posts
since Oct 2004
Oct 14th, 2004
0

Re: need help to create a java program

Hi Kumar,

Attempt to do your homework yourself, and then we can help you along the way. We do not do homework for you here.


Ed

Quote originally posted by kumar25 ...
hi all,
i am a beginner in java programming.Could anyone please provide source code for the following program.
A program that reads a integer and breaks it into a sequence of individual digits in reverse order.TQ.
Reputation Points: 17
Solved Threads: 1
Junior Poster
cosi is offline Offline
153 posts
since Aug 2004
Oct 14th, 2004
0

Re: need help to create a java program

Oh my, how many times must this be repeated?
Reputation Points: 17
Solved Threads: 8
Junior Poster in Training
Banderson is offline Offline
66 posts
since Aug 2004
Oct 14th, 2004
0

Re: need help to create a java program

If you're having trouble try reading in the integers into an array. Or you could turn the string into an array with the CopyTo() method or ToArray() methods.
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003
Oct 14th, 2004
0

Re: need help to create a java program

Here is how to reverse an inputed string, just apply it all to Int and you should have your program:

class ReverseString
Java Syntax (Toggle Plain Text)
  1. public class ReverseString
  2. {
  3. public String reverse(String arg)
  4. {
  5. String tmp = null;
  6. if (arg.length() == 1)
  7. {
  8. return arg;
  9. }
  10.  
  11. else
  12. {
  13.  
  14.  
  15. //extract the last char
  16. String lastChar = arg.substring(arg.length()-1,arg.length());
  17.  
  18.  
  19. //extract the remaining chars
  20. String remainingString = arg.substring(0, arg.length() -1);
  21.  
  22. tmp = lastChar + reverse(remainingString);
  23. return tmp;
  24.  
  25.  
  26. }
  27. }
  28. }

class TestReverse
Java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2.  
  3.  
  4. public class TestReverse
  5. {
  6. public static void main(String[] args) throws IOException
  7. {
  8. System.out.println("Enter a line to be reversed");
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10. String inData;
  11. inData = br.readLine();
  12. ReverseString rs = new ReverseString();
  13. System.out.println("Reversed: " + rs.reverse(inData));
  14. }
  15. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Oct 14th, 2004
0

Re: need help to create a java program

You can also get it to print the letters individually if you put the println() statement in the first class.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Oct 14th, 2004
0

Re: need help to create a java program

Quote originally posted by server_crash ...
Here is how to reverse an inputed string, just apply it all to Int and you should have your program:

class ReverseString
Java Syntax (Toggle Plain Text)
  1. public class ReverseString
  2. {
  3. public String reverse(String arg)
  4. {
  5. String tmp = null;
  6. if (arg.length() == 1)
  7. {
  8. return arg;
  9. }
  10.  
  11. else
  12. {
  13.  
  14.  
  15. //extract the last char
  16. String lastChar = arg.substring(arg.length()-1,arg.length());
  17.  
  18.  
  19. //extract the remaining chars
  20. String remainingString = arg.substring(0, arg.length() -1);
  21.  
  22. tmp = lastChar + reverse(remainingString);
  23. return tmp;
  24.  
  25.  
  26. }
  27. }
  28. }

class TestReverse
Java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2.  
  3.  
  4. public class TestReverse
  5. {
  6. public static void main(String[] args) throws IOException
  7. {
  8. System.out.println("Enter a line to be reversed");
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10. String inData;
  11. inData = br.readLine();
  12. ReverseString rs = new ReverseString();
  13. System.out.println("Reversed: " + rs.reverse(inData));
  14. }
  15. }

plz don't do like this..................
they should do the hw themselvs
Reputation Points: 10
Solved Threads: 0
Light Poster
tigerxx is offline Offline
35 posts
since Sep 2004
Oct 15th, 2004
0

Re: need help to create a java program

Quote originally posted by tigerxx ...
plz don't do like this..................
they should do the hw themselvs
VERY true.

We're here not to help people cheat, but to help people learn.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Jdic
Next Thread in Java Forum Timeline: Help With Contstructors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC