Results 1 to 3 of 3
- 11-30-2011, 06:54 AM #1
Prints Asterik in even columns and Minus in odd columns
The Result Should be like this
-*-*-
-*-*-
-*-*-
class Printdirect
{
public static void main(String[] args)
{
String r = "";
String u = "";
for (int i =1; i<=3 ; i++ )
{
for (int j =1; j<=5 ; j++ )
{
if (j%2 ==0)
{
r = r + "*";
r = r + "\n";
}
else
{
r = r + "-";
r = r + "\n";
}
}
System.out.println( r);
}
}
}
- 11-30-2011, 07:07 AM #2
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
Re: Prints Asterik in even columns and Minus in odd columns
[ spoonfeeding deleted - Jos ]
Last edited by JosAH; 11-30-2011 at 09:33 AM.
- 11-30-2011, 02:08 PM #3
Member
- Join Date
- Nov 2011
- Location
- Schijndel, Netherlands
- Posts
- 12
- Rep Power
- 0
Re: Prints Asterik in even columns and Minus in odd columns
If you put "\n" in a String, it will make a new line.
system.out.println(); as the method says, it prints a line.
There are 2 solutions:
You can either get rid of the "\n".
Or you can move the println outside the for-loop. And put the [ r = r + "\n"; ] inside the first for-loop (and delete it out of the second loop)
That should do the trick
Similar Threads
-
More columns in gridbox?!
By upanotch in forum AWT / SwingReplies: 4Last Post: 10-24-2011, 10:59 PM -
2D Array - Sum of columns
By dutchgold92 in forum New To JavaReplies: 2Last Post: 02-28-2011, 07:18 PM -
raw text to columns...
By ashishgaj in forum New To JavaReplies: 1Last Post: 02-02-2011, 06:29 PM -
Jlist Columns
By DenRed in forum New To JavaReplies: 2Last Post: 10-02-2009, 09:33 AM -
Using Columns With JTextField
By The Evil Genius in forum AWT / SwingReplies: 1Last Post: 03-17-2008, 01:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks