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

Write a Java application that displays an upside down triangle 4 lines high, mad

ID: 3927996 • Letter: W

Question

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.

Explanation / Answer

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

$ $ $ $

$ $ $

$ $

   $

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote