Quick Java Question

jessicak

Senior member
Aug 15, 2003
542
0
0
How do I take an integer parameter and use it to display a solid square of asterisks?
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
That wins the award for the most vague question ever. At least those trying to get others to do their homework try to ask a lucid question.
 

jessicak

Senior member
Aug 15, 2003
542
0
0
like let's say the user enters 3 for the number of sides they want on a square...then I need to make it look like this:

***
***
***
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
stick it in a loop....

like write a method:

public class test{
public static void main(String[]args){

int i = 4;
printSquare(i);
}

public static void printSquare(int i){
for(int k=0; k<i; k++){
for(int j = 0; j<i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
sorry the tabbing went to hell but my code works

do u understand it? its pretty simple
 

jessicak

Senior member
Aug 15, 2003
542
0
0
Originally posted by: RaynorWolfcastle
oh boy, if you can't figure this out on your own, programming may not be your thing.

oh you don't even understand, my teacher has taught nothing all school year so far and all of a sudden he's expecfting us to know how to write methods and stuff, I am trying to learn it though
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,107
4
81
get the number
print 4 times an * then at the end of that loop, put numTimes++;
prints that crap 4 times again
again
and again
ALL inside one big ass loop which stops when numTimes = input
 

clamum

Lifer
Feb 13, 2003
26,252
403
126
Objects Have Class! by David Poplawski is a good intro Java book. That's what we use... he's actually an instructor here. Haven't you had a good teacher that you wish taught every class? heh
 

johnjbruin

Diamond Member
Jul 17, 2001
4,401
1
0
Originally posted by: RaynorWolfcastle
oh boy, if you can't figure this out on your own, programming may not be your thing.

seriously. this should be known after sitting through lecture 1 of programming 101.