Write a Java application that displays an upside down triang
Solution
Hi, Please find my program.
Please let me know in case of any issue:
import java.util.Scanner;
public class TrianglePattern {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in); // to take user input
System.out.print(\"Input a number between 1-10: \");
int num = sc.nextInt();
char c = \'*\';
if(num%2 == 0)
c = \'$\';
int i, j, k;
for(i=4;i>=1;i--)
{
for(j=4;j>i;j--)
{
System.out.print(\" \");
}
for(k=1;k<=(i);k++)
{
System.out.print(c+\" \");
}
System.out.println();
}
}
}
/*
Sample run:
Input a number between 1-10: 8
$ $ $ $
$ $ $
$ $
$
*/
![Write a Java application that displays an upside down triangle 4 lines high, made up of one of two possible characters: asterisk [*] OR Dollar Sign [$]. The pr Write a Java application that displays an upside down triangle 4 lines high, made up of one of two possible characters: asterisk [*] OR Dollar Sign [$]. The pr](/WebImages/26/write-a-java-application-that-displays-an-upside-down-triang-1068184-1761559119-0.webp)
![Write a Java application that displays an upside down triangle 4 lines high, made up of one of two possible characters: asterisk [*] OR Dollar Sign [$]. The pr Write a Java application that displays an upside down triangle 4 lines high, made up of one of two possible characters: asterisk [*] OR Dollar Sign [$]. The pr](/WebImages/26/write-a-java-application-that-displays-an-upside-down-triang-1068184-1761559119-1.webp)