#1
Well, in my programming class, I wasn't really paying attention during the lesson on strings (kinda zoned out... My bad ). I figured out string lvl 1 on the exercise site since it was mostly logic based, but strings lvl 2 apparently requires things that I believe are called "loops". Anways, I have no ideas what these "loops" are... Can someone explain them to me, or link me to a site?

Given a string, return a string where for every char in the original, there are two chars.

doubleChar("The") → "TThhee"
doubleChar("AAbb") → "AAAAbbbb"
doubleChar("Hi-There") → "HHii--TThheerree"

Hint: Declare a local String result variable, starting with the empty string "". The standard loop over every char in a string is: "for (int i=0; i<str.length(); i++) { ...". Inside the loop, use "str.charAt(i)" or "str.substring(i, i+1)" to get each char, and add them to the result string with "=" and "+".

That's the problem...

Thanks.
Gear...
Peavey 5150, Squier, Ibanez RG2EX2, Yamaha F150, Ibanez RT150, MXR noisegate
#2
Well there are a bunch of options. I guess you can create a new string, and then concatenate each character twice as you iterate through the string..

String suckmyballs;
/* FOR LOOP */
//Concat str.charAt(i) to suckmyballs twice

Here is a for loop

for (int i = 0; i<poster.IQ(); i++){
System.out.println("Pay attention in class. \n");
}

Here is a while loop

while(poster.isDumbass() ){
System.out.println("Pay attention in class. \n");
}

Do while

do{
System.out.println("Pay attention in class. \n");
while(poster.isDumbass()
};

And finally. Everything in any programming language is google'able. It would be more beneficial for you to just google because what you will come up with are going to be tutorials so you can actually learn the concepts versus by example.
Last edited by Silentlassassin at Oct 2, 2008,
#3
Quote by Silentlassassin
Well there are a bunch of options. I guess you can create a new string, and then concatenate each character twice as you iterate through the string..

String suckmyballs;
/* FOR LOOP */
//Concat str.charAt(i) to suckmyballs twice

Here is a for loop

for (int i = 0; i<poster.IQ(); i++){
System.out.println("Pay attention in class. \n");
}

Here is a while loop

while(poster.isDumbass() ){
System.out.println("Pay attention in class. \n");
}

Do while

do{
System.out.println("Pay attention in class. \n");
while(poster.isDumbass()
};

And finally. Everything in any programming language is google'able. It would be more beneficial for you to just google because what you will come up with are going to be tutorials so you can actually learn the concepts versus by example.


lmao...just a word of advice, if you have a string called Suckmyballs in your program, you should probably change it before you turn it in...I leanred the hard way...lol


Anyways...my advice is to pay attention in class. Read your book. Look at the java docs. http://java.sun.com/j2se/1.4.2/docs/api/

and also, look at wikipedia. They have a lot of helpful things for programming. Not only are the articles good, but most contain links to tutorials and whatnot.
Quote by Sonicxlover
I once told a Metallica fan I liked Megadeth, and he stabbed me 42 times.
#4
No worries. I have fine coding ethics.

And to go along with what he said, also do not name your variables int x, string str and shit like that

It is meaningless to anyone who reads the program. What I used to think was, who cares.. who else will read this bs assignment. The Teacher.

And if they are douche bags, which isn't that far of a stress, that will mark you off as if it were the end of the world.

Since this language owns, use make-sensible names. For example..

Trying to find the area of a rectangle?

double x = bad
double length = good
double y = bad
double width = good

and lets say you have two boxes!!!

double length1
double length2

get where I am going?
#5
Quote by Silentlassassin
Well there are a bunch of options. I guess you can create a new string, and then concatenate each character twice as you iterate through the string..

String suckmyballs;
/* FOR LOOP */
//Concat str.charAt(i) to suckmyballs twice

Here is a for loop

for (int i = 0; i<poster.IQ(); i++){
System.out.println("Pay attention in class. \n");
}

Here is a while loop

while(poster.isDumbass() ){
System.out.println("Pay attention in class. \n");
}

Do while

do{
System.out.println("Pay attention in class. \n");
while(poster.isDumbass()
};

And finally. Everything in any programming language is google'able. It would be more beneficial for you to just google because what you will come up with are going to be tutorials so you can actually learn the concepts versus by example.


Well, I think I got the concepts with your examples...though it's not as if you've never zoned out in class, but I can't really be sure that you have... But my accusation can only be a fallacy if you're Jesus or something.

Thanks
Gear...
Peavey 5150, Squier, Ibanez RG2EX2, Yamaha F150, Ibanez RT150, MXR noisegate
#6
Hey. You can't blame me for trying to poke a little fun

But if you have any questions. contact me or something and I'll try to help you out.