print multiple lines
I am trying to figure out the best way to do the following problem. However i don't have any good idea. Thanks for your help.
//write a recursive Java method writeBlock that uses writeLine to write m
// lines of n characters. for example, writeBlock ('*' , 5 ) produce the
line *****.
> for example, writeBlock
> ('*' , 5 ) produce the
> line *****.
public void writeBlock(char ch,int m)
{
for(int i=0;i<m;i++)
System.out.println(ch);
}
Put this inside your main method.Don't forget the dukes.>
> > for example, writeBlock
> > ('*' , 5 ) produce the
> > line *****.
>
> > public void writeBlock(char ch,int m)
> {
> for(int i=0;i<m;i++)
> System.out.println(ch);
> }
>
>
> Put this inside your main method.Don't forget the
> dukes.
Maybe I'm crazy, but I don't quite see the recursion here.
> > > for example, writeBlock
> > > ('*' , 5 ) produce the
> > > line *****.
> >
> > > > public void writeBlock(char ch,int m)
> > {
> > for(int i=0;i<m;i++)
> > System.out.println(ch);
> > }
> >
> >
> > Put this inside your main method.Don't forget the
> > dukes.
>
> Maybe I'm crazy, but I don't quite see the recursion
> here.
And I have overlooked the word recursive in his post.****
public class test
{
public static void main(String args[])
{
writeBlock('*',6);
}
public static void writeBlock(char ch,int m)
{
if(m==0)
return;
writeBlock(ch,m-1);
System.out.print(ch);
return;
}
}
> don't forget the dukesNot quite there yet. Did you notice "to write m lines of n characters"?PS It might be a good idea to let the op put some effort into it =)
> Put this inside your main method.Don't forget the> dukes.Quest, please stop helping people to cheat. You have seen the reasons why it is discouraged here before.
> Quest, please stop helping people to cheat. You
> have seen the reasons why it is discouraged here
> before.
Even I discourage people doing someone else's homework.Blame it on the dukes.It's better Sun gets rid of that star at the top.A serious distraction!Sometimes when i am high on duke drugs i can't resist.
> > Quest, please stop helping people to cheat. You
> > have seen the reasons why it is discouraged here
> > before.
>
> Even I discourage people doing someone else's
> homework.
I guess that makes you a hypocrite.
> Blame it on the dukes.
Rather that you take responsibility for your own actions. Of course.
>It's better Sun gets
> rid of that star at the top.A serious
> distraction!Sometimes when i am high on duke drugs i
> can't resist.
Duke Drugs? Now you are just making things up.