I have to display the following pattern using a loop:
@@@@@@@@@&
@@@@@@@@&&
@@@@@@@&&&
@@@@@@&&&&
@@@@@&&&&&
@@@@&&&&&&
@@@&&&&&&&
@@&&&&&&&&
@&&&&&&&&&
I have the following program that is using a loop but it displays 9 rows of 10 @ symbols instead of incorporating the & symbols.
What do I need to do to make it work to display like the picture above?
public class Symbols
{
private int width;
public Symbols(int aWidth)
{
width = aWidth;
}
public String toString()
{
String r = "";
for (int i = 1; i<= width; i++)
{
for(int j = 1; j<= width; j++)
r = r +"@";
r = r + "\n";
}
return r;
}
}
public class SymbolsTester
{
public static void main(String [] args)
{
Symbols symbols = new Symbols(9);
System.out.println(symbols.toString());
}
}