Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

going to In this part, you will use loops to print out ASCII art. Specifically,

ID: 3662429 • Letter: G

Question

going to In this part, you will use loops to print out ASCII art. Specifically, we're The catch is, it needs to be whatever size the user enters. "size" refers to the height (in lines) of one of the individual 3 shaded-in triangles. For example, in the triforce shown previously, size=5. The details: . All code needs to go in "Triforce.java" It should just prompt the user for a size, then print a triforce, then exit. Use "" as the shading character. Here are some other examples: $ java Triforce Enter size 1

Explanation / Answer


package triforce;

import java.util.Scanner;

public class Triforce {

public static void main(String[] args) {
System.out.println("Enter size: ");
Scanner s=new Scanner(System.in);
int size=s.nextInt();
int x, y, z;
int i=1;
for (y = size*2; y >= 1; y--) { //reverse here
if(y>size)
{
for (x = 0; x < size*2 - y; x++)
System.out.print(" ");

for (x = (2 - y); x < (2 - y) + (2 * y - 1)/2-i/size; x++)
{
System.out.print("#");
i++;   
}
for(x=(2 - y) + (2 * y - 1)/2-i/size; x<2+y+i/size;x++)
{
System.out.print(" ");
i++;
}
for (x = (2 + y) ; x < (2 + y) + (2 * y + 1)/2-i/size; x++)
{
System.out.print("&");
i++;
}
  
}
else
{
for (x = 0; x < size*2 - y; x++)
System.out.print(' ');
for (x = (2 - y); x < (2 - y) + (2 * y - 1); x++)
{
  
System.out.print("#");
}
}
System.out.print(' ');
}
}
  
}