Write a Java application that displays an upside down triang

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 program will ask a user to enter one number between 1 and 10. If the number is odd, the triangle will be made up of asterisks; if the number is even it will be made up of $ characters. Sample outputs: Input a number between 1-10: 7 Provide a printout of properly formatted source code (your entire Java program). Provide 2 example outputs/test cases: one that shows a printout of asterisks and one that shows a printout of $ characters.

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site