I Need Help!!

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

Join Date: Aug 2005
Posts: 3
Reputation: dmart is an unknown quantity at this point 
Solved Threads: 0
dmart dmart is offline Offline
Newbie Poster

I Need Help!!

 
0
  #1
Aug 11th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: I Need Help!!

 
0
  #2
Aug 11th, 2005
Hi everyone,

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 3
Reputation: dmart is an unknown quantity at this point 
Solved Threads: 0
dmart dmart is offline Offline
Newbie Poster

Re: I Need Help!!

 
0
  #3
Aug 11th, 2005
what does that mean? do i have to use an array or something?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 102
Reputation: yni420 is an unknown quantity at this point 
Solved Threads: 0
yni420's Avatar
yni420 yni420 is offline Offline
Junior Poster

Re: I Need Help!!

 
0
  #4
Aug 11th, 2005
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
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 55
Reputation: NPH is an unknown quantity at this point 
Solved Threads: 1
NPH NPH is offline Offline
Junior Poster in Training

Re: I Need Help!!

 
0
  #5
Aug 12th, 2005
Here is the code you need. Read the comments to understand it.
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;
		}
	}
}
  1. talk("321cba");
For more help, www.NeedProgrammingHelp.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: I Need Help!!

 
0
  #6
Aug 12th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: I Need Help!!

 
0
  #7
Aug 12th, 2005
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
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
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the Java Forum


Views: 1557 | Replies: 6
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC