•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,762 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3862 | Replies: 7
![]() |
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
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.
•
•
Join Date: Aug 2004
Location: North Carolina
Posts: 25
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
Join Date: Jul 2003
Location: Bamberg, Germany
Posts: 117
Reputation:
Rep Power: 6
Solved Threads: 2
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.
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
Here is how to reverse an inputed string, just apply it all to Int and you should have your program:
class ReverseString
class TestReverse
class ReverseString
public class ReverseString
{
public String reverse(String arg)
{
String tmp = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last char
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining chars
String remainingString = arg.substring(0, arg.length() -1);
tmp = lastChar + reverse(remainingString);
return tmp;
}
}
}class TestReverse
import java.io.*;
public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
You can also get it to print the letters individually if you put the println() statement in the first class.
•
•
Join Date: Sep 2004
Posts: 35
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
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
public class ReverseString { public String reverse(String arg) { String tmp = null; if (arg.length() == 1) { return arg; } else { //extract the last char String lastChar = arg.substring(arg.length()-1,arg.length()); //extract the remaining chars String remainingString = arg.substring(0, arg.length() -1); tmp = lastChar + reverse(remainingString); return tmp; } } }
class TestReverse
import java.io.*; public class TestReverse { public static void main(String[] args) throws IOException { System.out.println("Enter a line to be reversed"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String inData; inData = br.readLine(); ReverseString rs = new ReverseString(); System.out.println("Reversed: " + rs.reverse(inData)); } }
plz don't do like this..................
they should do the hw themselvs
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation:
Rep Power: 11
Solved Threads: 101
•
•
•
•
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- put the Dos 's command into java program? (Java)
- Help with Java program writing (Java)
- JAVA program help (Student/Grades) (Java)
- Help with a java program home work assignment (Java)
- Java Question (Java)
Other Threads in the Java Forum
- Previous Thread: Jdic
- Next Thread: Help With Contstructors


Linear Mode