need help to create a java program

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Oct 2004
Posts: 1
Reputation: kumar25 is an unknown quantity at this point 
Solved Threads: 0
kumar25 kumar25 is offline Offline
Newbie Poster

need help to create a java program

 
0
  #1
Oct 14th, 2004
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.
Quick reply to this message  
Join Date: Aug 2004
Posts: 153
Reputation: cosi is an unknown quantity at this point 
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: need help to create a java program

 
0
  #2
Oct 14th, 2004
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

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.
In a world without walls or fences,
What use are Windows and Gates.
Quick reply to this message  
Join Date: Aug 2004
Posts: 47
Reputation: Banderson is an unknown quantity at this point 
Solved Threads: 4
Banderson's Avatar
Banderson Banderson is offline Offline
Light Poster

Re: need help to create a java program

 
0
  #3
Oct 14th, 2004
Oh my, how many times must this be repeated?
Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: need help to create a java program

 
0
  #4
Oct 14th, 2004
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.
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: need help to create a java program

 
0
  #5
Oct 14th, 2004
Here is how to reverse an inputed string, just apply it all to Int and you should have your program:

class ReverseString
  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
  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. }
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: need help to create a java program

 
0
  #6
Oct 14th, 2004
You can also get it to print the letters individually if you put the println() statement in the first class.
Quick reply to this message  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: need help to create a java program

 
0
  #7
Oct 14th, 2004
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
  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
  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
Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: need help to create a java program

 
0
  #8
Oct 15th, 2004
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.
Alex Cavnar, aka alc6379
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC