May I know how to split a word into individual characters (letters)?
For example, AUGC into
A
U
G
C

Recommended Answers

All 31 Replies

What do you think the "toCharArray" method of String is for?

See the API docs for String.

@Sunshineserene you use the charAt() method. Infact here I have developed for you a Java Program that will accept your name and four of your friends names and then reverse AUGC to CGUA and friends names reversed respectively for any five names. Bet when you go through the program your will understand use of charAt():

/**
 * @(#)NameArray.java
 *
 */
import java.util.Scanner;//assist to read user input from console
public class NameArray {
    public static void main(String args[])
    {
    	//declare the variables
    	String[] strName;
    	String Reversedname;
    	int Count,Counting=1;
    	strName = new String[5];
    	//get the five names from the user
    	for(Count=0;Count<5;Count++)
    	{
		    Scanner scanner = new Scanner(System.in);
		    System.out.print("Enter your name for friend "+ Counting + ": ");
		    strName[Count] = scanner.nextLine();
		    Counting++;
    	}
    	Counting=1;
    	//print the names entered in reverse order
    	System.out.println("\n\n Results");
    	for (Count=0;Count<5;Count++)
    	{
    		Reversedname = reverse(strName[Count]);//invoke the reverse method
		    System.out.println("Name " + Counting + " reserved is "+ Reversedname);
		    Counting++;
    	}
    }
    //reverse method
    public static String reverse(String sName)
    {
    	String Result=" ";
    	int counter,length;
    	length = sName.length()-1;
    	for(counter=length;counter>=0;counter--)
    	{
    		Result = Result + sName.charAt(counter);		
    	}
    	return(Result);
    }
    
}

See in red the use of charAt() method.

commented: The "code of conduct" on this site dictates that we not post full code solutions. -2

mbugua, do you consider the OP too stupid to understand the first reply so that you found it necessary to do his homework for him?

Masijade indeed if this is his homework, Sunshineserene should be advised to avoid copying it because I must have been out of my mind to post the code:

Sunshineserene I understand your concern just study the charAt() method.

Masijade indeed if this is his homework, Sunshineserene should be advised to avoid copying it because I must have been out of my mind to post the code:

Sunshineserene I understand your concern just study the charAt() method.

Oh C'mon how can you think it is not homework? What real-world application would ever need what is descibed there? And, knowing that, how do you think that doing it for him teaches him anything? He'll take it and hand it in and that's that, and tommorrow he will be even more lost than he was today.

However, if you insist on continuing to do homework for people, hopefully they come to work at the same company you work for (if you even do, yet, or ever) so that you can continue doing their work for them and let them get paid for it and you eventually get fired since your own work is not getting done.

It is homework, but the codes he gave is actually not what I want. And hey, be nice? He's just trying to help. Don't quarrel. Peace.

Point taken, especially that no effort by Sunshineserene in at least delivering a sample code. ...That is the point...we should point that out to him, but do not be obsessed by the fact that you are doing homework for people, that you are helping people and that kind of stuff!!!! If these guys want their homework done, there are many avenues of doing such including paying to get perfect code.

It's close to what you're looking for. Write a program using charAt(). The sample one provided (or a google search, or browsing through the java library) will give you a good idea of how to use it. Then it's just implementing the method in your program. Good luck!

Point taken, especially that no effort by Sunshineserene in at least delivering a sample code. ...That is the point...we should point that out to him, but do not be obsessed by the fact that you are doing homework for people, that you are helping people and that kind of stuff!!!! If these guys want their homework done, there are many avenues of doing such including paying to get perfect code.

No. The point is that he should write the code and others here should help him crrect it. The code should come from him and not you. Give a few hints at to what is to be done and let him do it. If it doesn't work he should post that code and ask for further help/clarification. Then you give him the next clue(s) as to what he has done wrong and let him try again. You still do not post a complete code. Repeat the process until the problem is solved. Guaranteed something will have been learned in that process in a manner that will stick. Normally, when provided with code, even if they do look at it and say "Oh, okay, now I understand", it is still something that is, normally, quickly forgotten, and so, useless.

I am responding to this for the last time because I notice you are a moderator "I do not know of what". What you are suggesting makes sense but not all the time, let me remind you that you should not be obsessed with your way of doing things. Take the case of this thread if you visit http://www.daniweb.com/forums/thread293951.html you will notice that the guy is working on a "bioinformatics project on dynamic programming" whatever that is. My take is that what he asked in this thread is a drop in the ocean of what he is to implement. Do not tell me that informing him of charAt() and a sample of its usage will help complete his project, on the contrary he will learn from the code and concentrate on its application.....NOT SYNTAX..... If you gave him the right direction the first time, we would not be discussing this...finally mind your language boy....being rude to people does not mean they will learn more..rather you put them off...

Yes Mbugua, I agree with you. Masijade I think you are very rude when replying too. Mbugua, I'm sorry about what happened, and also, thank you for your help. (:

You are welcome.

Edit: Nevermind.

I totally agree with you toCharArray() will provide a better alternative.

ther's a simple program 4 tat. Here it is............
u can use this method if u hv finished String class

import java.io.*;
class split
{
public static void main()throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
String a;
int i,j;
char c;
System.out.println("Enter a word to split the letters");
a=x.readLine();
for(i=0;i<a.length();i++)
{
c=a.charAt(i);
System.out.println(c);
}}}

1. THis is an old thread, July 5th - 7th.
2. Most of the thread is a discussion about why you should not post solutions to other people's homework. So why did you post a solution? It's not even a good example of Java code.

My friend Megha SR take off before this guys do to you what they enjoy doing best "tear you apart and leave you for the dogs". Get a forum where you can openly express your views without fear of reproach....Here they only enjoy listening to themselves...its no longer a learning place but a Dungeon...

commented: No content and no meaning and no help. Go somewhere else to complain. Show effort and won't "get torn about", but you're probably not interested in that. -2
commented: Nonsense on stilts. +0

The code has already been provided posts ago.
It has been also established that we shouldn't give ready code, rather than help the poster find the solution.

Now why do you think mnmw, that Megha's post had any meaning?

He posted code that had already been posted and gave solution with no further explanation and without teaching anything. And that happened 1 month later.

Not to mention that the code is not correct. That is not the right way to write code. If someone follows that example they will learn nothing.

Now explain what good does Megha's code have or what did his post contributed?

See I told you, they have nothing good to offer apart from satisfying their egos.
Sadly, in this forum, we are not provided with a means of opting-out of future communication. All the 812,117 members are already locked to the mercy of a few mean guys.

commented: More whining. -2
commented: Holy missing the point of the whole exercise, Batman! +0

Sounds like someone who didn't get a cut-n-paste answer for his homework.

commented: Mean and Arrogant +0

Sadly, in this forum, we are not provided with a means of opting-out of future communication. All the 812,117 members are already locked to the mercy of a few mean guys.

You can unsubscribe from a thread in your subscribed threads listing in the Control Panel. You may also chose not to receive email notification of replies in threads.

You do have the option to manage your communications from this site.

Opting-out of future communication, I mean closing my account so that the likes of masijade do not have to satisfy their egos by deducting marks and those kind of stupid things.

Edit: Nevermind.

And why do you Masijade misuse your privilege by deleting your content so that the next poster looks stupid. This is very unethical and stupid of you.

Masijade, have you ever paused for a second to take stock of your contribution to this forum? Have you realized that you have not contributed any new knowledge in the site from your 2,998 posts apart from riding on peoples’ backs. Or is this the usual work of a system administrator of maintenance and customer support ….whining boy!
I give you a challenge, create new knowledge by advising Dani on how I can close my account without the site crumbling, and you will have done yourself some service.

commented: This is absolutely ignorant. You obviously didn't look very closely at his posting history. -2

Masijade, have you ever paused for a second to take stock of your contribution to this forum? Have you realized that you have not contributed any new knowledge in the site from your 2,998 posts apart from riding on peoples’ backs.

I don't think anybody here really needs this pointed out, but man, that's the dumbest opinion anybody's put forward in my presence, real or virtual, in a long, long time. Holy cats, that's up there with "gosh, we'll invade Afghanistan, what could go wrong?" on the list of really stupid things that people have said over the years. It's not quite up there with "Waiter! Four orders of fugu please!", in that you didn't keel over dead just after saying it, but it does show a similarly keen grasp of the facts of the world around you.

mnmw - if that is your real name... - I wish you all the luck in the world in deleting your account. The sooner the better, I say.

See I told you, they have nothing good to offer apart from satisfying their egos.
Sadly, in this forum, we are not provided with a means of opting-out of future communication. All the 812,117 members are already locked to the mercy of a few mean guys.

You still haven't answered my question in my only post here:
>
Now explain what good does Megha's code have or what did his post contributed?
<

And please answer with arguments, not just flaming what you don't like. You accuse us of being judgmental but all of our posts contained arguments backing up our position. (eg. By providing ready code to new programmers will not help them learn.)

Now I also expect a solid answer to my above question with solid arguments.


EDIT: jon.kiparsky can you explain the joke you made: "Waiter! Four orders of fugu please!"

fugu - a fish used in Japanese sushi. Claimed to be the best tasting of all, but parts of it are incredibly pooisonous. So if the chef makes a tiny mistake in preparing it you die in agony wuthin 24 hours. There is no known antidote or cure. No, I'm not joking, this is real. People really do eat it, despite the risk.

And why do you Masijade misuse your privilege by deleting your content so that the next poster looks stupid. This is very unethical and stupid of you.

Anyone can edit there own post. And the editing (in my case) always takes place before the next reply.

Masijade, have you ever paused for a second to take stock of your contribution to this forum? Have you realized that you have not contributed any new knowledge in the site from your 2,998 posts apart from riding on peoples’ backs. Or is this the usual work of a system administrator of maintenance and customer support ….whining boy!
I give you a challenge, create new knowledge by advising Dani on how I can close my account without the site crumbling, and you will have done yourself some service.

http://www.daniweb.com/forums/thread302711.html
http://www.daniweb.com/forums/thread296585.html
http://www.daniweb.com/forums/thread185271.html
http://www.daniweb.com/forums/thread178219.html
http://www.daniweb.com/forums/thread76039.html
http://www.daniweb.com/forums/post1174487.html#post1174487

Just to provide a few examples. Now, I have no idea why I am even attempting to defend myself to someone like you, but, now, tell me again how I contribute nothing here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.