question for java
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!
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.
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.
You guys really thik this is homework. I doubt it.
Something like this:
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
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
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
Popular Topics
Advertisement