Raydon
08-28-2002, 04:26 AM
I need a simple script/program that run like this:
Write a program Lab02.java to draw a squared pattern like this:
D:\it1002>java Lab02
> Give height: 12
+-+-+-+-+-+-
-+-+-+-+-+-+
+-+-+-+-+-+-
-+-+-+-+-+-+
+-+-+-+-+-+-
-+-+-+-+-+-+
+-+-+-+-+-+-
-+-+-+-+-+-+
+-+-+-+-+-+-
-+-+-+-+-+-+
+-+-+-+-+-+-
-+-+-+-+-+-+
Anyone can help me ? Willing to pay to get it done. This is an assignment from my school, but can't seems to figure it out !
Need it by Friday!!
Aplusmedia
08-28-2002, 07:20 AM
use the for statement,
something like..
int number;
number = readInt();
for (int i = 0; i <=12;i++){
System.out.println("-+-+-+-+-+-+");
}
or since very second line,,the output is different..you may want to halve the number then replace:
System.out.println("-+-+-+-+-+-+");
with
System.out.println("-+-+-+-+-+-+\n+-+-+-+-+-+-");
NOTE: this is not actual code..but it may help to guide you through it.
Raydon
08-28-2002, 09:39 AM
Thanks for ya help, but the print must be ("+"),("-") and not ("-+-+-+-+-+-+"), and that is the tedious part.
I had tried it for days without getting it right.
:confused:
Originally posted by Aplusmedia
use the for statement,
something like..
int number;
number = readInt();
for (int i = 0; i <=12;i++){
System.out.println("-+-+-+-+-+-+");
}
or since very second line,,the output is different..you may want to halve the number then replace:
System.out.println("-+-+-+-+-+-+");
with
System.out.println("-+-+-+-+-+-+\n+-+-+-+-+-+-");
NOTE: this is not actual code..but it may help to guide you through it.
Aplusmedia
08-28-2002, 10:10 AM
then use "while" and "for" and "if"
int number;
int line = number -1;
number = readInt();
while (line < number && > 0){
for(int i = 0;i<=number;i++){
if (i > 0) System.out.print("+")
if (i > 0) System.out.print("-");
}//end for
line --;
}//end while
in the for loop...it'll print "+" and "-" until it reaches given number (12)
all this will happen while number of line is greater than 0, it decrement everytime it has finish printing a complete line of -+-+-+
this may not work exactly as you want..im just writing what ever comes in my head as i type. but you can play around...i think that code(psuedocode :stickout may work)
if not..try kasamba.com
ckpeter
08-28-2002, 10:55 AM
Aplusmedia has been very helpful, but if you still need help, post the code you already have first, so we can pinpoint the problem for you.
We can help, but we can't do your homework for you.
Peter
cyansmoker
08-28-2002, 10:59 AM
Guys-,
not to rain on your parade, but obviously this is a lab assignement.
You're not doing the guy -or his fellow students- any favour by giving him the solution in a nutshell.
The goal of assignements is to use your acquired knowledge in a smart manner, hence helping you make progress.
Aplusmedia
08-28-2002, 11:23 AM
well...i didnt give him the code, what i given him is a starting point..where he can then try and solve it.
Magoo
08-29-2002, 09:10 PM
You can do something like this:
lines=12;
for (int i=0; i<lines; i++){
Magoo
08-29-2002, 09:15 PM
Try something like this:
int lines=12;
String symbol="-";
StringBuffer sb = new StringBuffer();
for (int x=0; i<lines; x++){
for (int y=0; y<lines; y++){
if (symbol.equals("-") symbol="+";
else symbol="-";
sb.append(symbol);
}
sb.append("\n");
}
System.out.println(sb.toString());
}
ckpeter
08-29-2002, 10:26 PM
Magoo, it is not good for you to write code for him; he should learn on his own.
Besides, the way you coded it is too complicated and not to the spirit of the original assignment.
Peter
cyansmoker
08-30-2002, 01:37 AM
I think, if Raydon did submit here what he has done so far, we would be more than happy to point out why it's not working.