Closed Thread Icon

Preserved Topic: I want to repeat in Java (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21174" title="Pages that link to Preserved Topic: I want to repeat in Java (Page 1 of 1)" rel="nofollow" >Preserved Topic: I want to repeat in Java <span class="small">(Page 1 of 1)</span>\

 
viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 11-17-2002 21:05

Hi Java experts.
Is there a command for Java that would allow me to repeat the same character a certain number of times, like:

- I want to print "**********", so I need a command like

repeat("*", 10) , i.e., repeat the character "*" ten times.

Is there such a command in Java (note that my "repeat" is just an example).

??

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 11-17-2002 21:10


public void repeat(String c,int amount) {

String strng = new String();

for(int i=0;i<amount;i++) {
strng += c; // <- Not sure if this line works.
}
System.out.println(strng)

}

I haven't done Strings in College yet, and its been four or so years since I was doing it myself. But that shouldnt be too wrong.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 11-17-2002 21:16

Over to server-side scripting for this.

___________________
Emps

FAQs: Emperor

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 11-17-2002 21:19

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 11-17-2002 21:25

Thank you guys.
I'm gonna use your ideas but actually my question was: is there a "repeat" command built-in in Java language, ready to be used, like substring() and others?

I guess you answered the question and the answer is: "No! - You have to code your own "repeat" method".

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 11-17-2002 21:30

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 11-17-2002 21:46

If I remember my old times of Visual Basic, there were such a simple built-in instruction in that language and it was named repeat()... I'm not sure.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 11-17-2002 22:11

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« BackwardsOnwards »

Show Forum Drop Down Menu