I’ve got an issue where it’s not printing out like it should and cannot figure out what it is.
right now my code is printing out this:
***#
***##
***###
when it should be printing out like this:
***#
**##
*###
Here’s my code as it stands now:
import static java.lang.System.*;
public class Box
{
private int size;
public Box()
{
}
public Box(int count)
{
size = count;
}
public void setSize(int count)
{
size = count;
}
public int getSize()
{
return size;
}
public String toString()
{
String output="";
for(int i = 1; i <= size; i++)
{
for(int k = size; k >0; k--)
{
output += "*";
}
for(int j = size; j >size-i; j--)
{
output += "#";
}
output += "\n";
}
return output;
}
}
and my runner class for cross-referencing:
import static java.lang.System.*;
import java.util.Scanner;
public class Lab11e
{
public static void main( String args[] )
{
Scanner keyboard = new Scanner(System.in);
String choice="";
do{
out.print("Enter the size of the box : ");
int big = keyboard.nextInt();
//out.print("Enter a letter : ");
//String value = keyboard.next();
//instantiate a TriangleFour object
Box box = new Box( big);
//call the toString method to print the triangle
System.out.println( box );
System.out.print("Do you want to enter more data? ");
choice=keyboard.next();
}while(choice.equals("Y")||choice.equals("y"));
}
}
My thoughts are that I’m very close to getting it but just can’t figure out what.
Solution with two inner loops: