Java Exercises - Methods


 

  1. Write a method printTriangle that has a char parameter c and an int parameter n.  The method should print a triangular pattern with the perimeter consisting of the character c and the interior (if there is one) consisting of blanks.  For example, the call printTriangle('*',5); should produce the following output:

    *

    **

    * *

    *  *

    *****

     

  2. Write a method called convertToGrade that returns a char value, and accepts an int parameter called mark.  The method should return the letter grade that corresponds to the value of mark (A, B, C, D, or F).  If the method receives an invalid value (outside of 0-100), it returns the character 'X'.