| | |
I Need Help!!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 3
Reputation:
Solved Threads: 0
i have the following code that reads user input characters and displays the string entered in reverse order.
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ReverseString {
public String reverse(String arg)
{
String input = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last character entered
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining characters
String remainingChar = arg.substring(0, arg.length() -1);
input = lastChar + reverse(remainingChar);
return input;
}
}
}
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class TestReverseString
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter string values.");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputData;
inputData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println(rs.reverse(inputData));
}
}
If abc123 is entered, 321cba is returned. How do I get the program to return three two one cba? In other words, I need to spell out the numeric values that are entered.
thanks for your time fellas
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ReverseString {
public String reverse(String arg)
{
String input = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last character entered
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining characters
String remainingChar = arg.substring(0, arg.length() -1);
input = lastChar + reverse(remainingChar);
return input;
}
}
}
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class TestReverseString
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter string values.");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputData;
inputData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println(rs.reverse(inputData));
}
}
If abc123 is entered, 321cba is returned. How do I get the program to return three two one cba? In other words, I need to spell out the numeric values that are entered.
thanks for your time fellas
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
You have to pass each numerical value thus its something down the lines of writing your own parser
Yours Sincerely
Richard West
You have to pass each numerical value thus its something down the lines of writing your own parser
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
why dont you use some switch statement to see whether the char entered is number or what and the convert it to the appropriate string value?
you can loop through the string using for
you can loop through the string using for
Creationz Unlimited - Software ,web , forums , graphic work , Logos
Dreamzsportz Online - Want your big break in sports?
Kakkanat Home Stay - Plan your next vacation to India
Dreamzsportz Online - Want your big break in sports?
Kakkanat Home Stay - Plan your next vacation to India
•
•
Join Date: May 2005
Posts: 55
Reputation:
Solved Threads: 1
Here is the code you need. Read the comments to understand it.
For more help, www.NeedProgrammingHelp.com
public static void talk(String numbersAndLetters)
{
//go through the string's characters
for (int i = 0; i< numbersAndLetters.length(); i++)
{
//get a char
char currentChar = numbersAndLetters.charAt(i);
//switch on the char
switch(currentChar)
{
//if its 1 print one
case '1':
System.out.print("one "); break;
//if its 2 print two
case '2':
System.out.print("two "); break;
//if its 3 print three
case '3':
System.out.print("three "); break;
//if its 4 print four
case '4':
System.out.print("four "); break;
//if its 5 print five
case '5':
System.out.print("five "); break;
//if its 6 print six
case '6':
System.out.print("six "); break;
//if its 7 print seven
case '7':
System.out.print("seven "); break;
//if its 8 print eight
case '8':
System.out.print("eight "); break;
//if its 9 print nine
case '9':
System.out.print("nine "); break;
//otherwise the char is not a number - just print it out
default:
System.out.print(currentChar); break;
}
}
} Java Syntax (Toggle Plain Text)
talk("321cba");
NPH, DO NOT do peoples' homework for them. It makes sure these people never learn a thing (or rather that all they learn is that there's always a sucker stupid enough to do their work for them).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
NPH actually jwenting is right about this. I don't mean to be mean but i used to do this sometime back(i think jwenting remembers) and after a while these students started flooding my emails asking me to do their homework.
There was one week when i got 20 requests in my email for me to do their homework. I don't mind helping out and writing a few methods here and there but some of them asked me to write an entire application for them. There was one request i got asking me to write an entire word editor for him and send him the code.
I apologize if i sound mean as that's not what i am trying to do
Yours Sincerely
Richard West
NPH actually jwenting is right about this. I don't mean to be mean but i used to do this sometime back(i think jwenting remembers) and after a while these students started flooding my emails asking me to do their homework.
There was one week when i got 20 requests in my email for me to do their homework. I don't mind helping out and writing a few methods here and there but some of them asked me to write an entire application for them. There was one request i got asking me to write an entire word editor for him and send him the code.
I apologize if i sound mean as that's not what i am trying to do
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Other Threads in the Java Forum
- Previous Thread: Can Anyone Help Me Please?
- Next Thread: Abstract Error Message
Views: 1557 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited webservices windows






