question for java

Started by
7 comments, last by Qw3r7yU10p! 19 years, 6 months ago
how do we convert statement like A whale! Down it goes, and more and more... up goes its tail! to A WhalE! DowN IT GoeS, AnD MorE AnD MorE... UP GoeS ItS TaiL!
Advertisement
We read our textbooks and don't ask people online to do our homework for us.
-----BEGIN GEEK CODE BLOCK-----Version: 3.12GCS/M/S d->+(++) s+: a19? C++++ UL++ P+++ L+ !E W+++ N+ o++ K? w!O M-- V? !PS PE Y+ PGP t++ 5+++ X R tv+> b+(++)>+++ DI+++>+++++ D++G e>++++ h! r y?------END GEEK CODE BLOCK------
String original;

if (original == "A whale! Down it goes, and more and more... up goes its tail!") {
original = "A WhalE! DowN IT GoeS, AnD MorE AnD MorE... UP GoeS ItS TaiL!"
}


Easy.
.equals() you mean?
You guys really thik this is homework. I doubt it.

Something like this:

char *str = "Whatever";int len = strlen(str);for(int i = 0; i < len; i++){if(str == ' '){if(i > 0){MakeBig(i-1);}if(i < len-1){MakeBig(i+1);}}


For the MakeBig-Functio look at the umerical represetation of ascii characters. Im pretty sure you just add a constant to the character value. Otherwise youll just have to make a switch statemet contaiig all characters.

-CProgrammer
damnit. Forgot that you were using java.
Well it should be similar.
Quote:Original post by CProgrammer
You guys really thik this is homework. I doubt it.

You really think this could be anything other than homework. I doubt it.
Quote:Original post by CProgrammer
damnit. Forgot that you were using java.
Well it should be similar.

I bet he goes on to post a thread of "How do I change this C code into Java?" now.

shmoove
Quote:Original post by AVigesaa
.equals() you mean?


Nope, I meant ==

I was assuming that the original text would come from another literal.
Quote:Original post by ryonckc2004
how do we convert statement like

A whale! Down it goes, and more and more... up goes its tail!

to

A WhalE! DowN IT GoeS, AnD MorE AnD MorE... UP GoeS ItS TaiL!


In C++

#include <string>#include <algorithm>#include <iostream>#include <cctype>struct MakeFirstAndLastLetterUpperCase {    char* previousCharacter;    MakeFirstAndLastLetterUpperCase() : previousCharacter(0) {    }    void operator()(char& c) {        if(previousCharacter) {            if(!isalpha(*previousCharacter)) {                if(isalpha(c)) {                    c = toupper(c);		    }		}            else {                if(!isalpha(c)) {                    *previousCharacter = toupper(*previousCharacter);	          }		}        }        previousCharacter = &c;    }};int main() {	std::string str = "A whale! Down it goes, and more and more... up goes its tail!";	std::cout << str << std::endl;	std::for_each(str.begin(), str.end(), MakeFirstAndLastLetterUpperCase());	std::cout << str << std::endl;	return 0;}

This topic is closed to new replies.

Advertisement