Question

In: Computer Science

Write a user-defined function named printBox that, when called, will output the following sequence of characters:...

  1. Write a user-defined function named printBox that, when called, will output the following sequence of characters:

OOOOOOOO

OOOOOOOO

OO            OO

OO            OO

OOOOOOOO

OOOOOOOO

  1. Write a user-defined function named printArrow that, when called, will accept an integer called arrowSize and will output a sequence of *’s such that there are arrowSize number of rows with the number of * incrementing, and then arrowSize-1 rows with the number of * decrementing:
    1. If arrowSize = 3, then the output is:

*

**

***

**

*

  1. If the arrowSize = 5, then the output is:

*

**

***

****

*****

****

***

**

*

And so on…

(Hint: you will need two for-loops in a for-loop)

Solutions

Expert Solution


import java.util.*;
public class Solution {
// printBox method
   static void printBox() {
       for(int i=0; i<6; i++) {
           for(int j=0; j<8; j++) {
               if((i==2 && j>1 && j<6) || (i==3 && j>1 && j<6)) // Check the condition

System.out.print(" ");
               else

System.out.print(" O ");
           }
           System.out.println(); // For enter the new line.
       }
   }
// printArrow method taking arrowSize as a parameter
   static void printArrow(int arrowSize) {
       int i=0, j=0, k=0, l=1;
       for(i=0; i<arrowSize*2; i++) { // Outer loop
           if(i<=arrowSize) {
               for(j=0; j<i; j++) { // Inner loop
                   System.out.print("* ");
               }
               System.out.println();
           }else {
               for(k=0; k<arrowSize-l; k++) { // Inner loop
                   System.out.print("* ");
               }
               l++;
               System.out.println(); // For enter the new line.
           }
       }
      
   }

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       printBox(); // Call the printBox method.
       printArrow(scan.nextInt()); // Call the printArrow method.
       printArrow(scan.nextInt()); // Call the printArrow method.

   }

}

Output :



Related Solutions

Write a user defined function named “findTwosComplement” in C++, which will find 2’s complement of a...
Write a user defined function named “findTwosComplement” in C++, which will find 2’s complement of a signed number. Input must be passed by reference to the function and it will return the answer. There is no need to call this function anywhere. You can use following operators only: <<>> ~ & ^ | Decimal
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
(EXCEL) Create a user-defined function called Hexagon that takes one argument called side and returns the...
(EXCEL) Create a user-defined function called Hexagon that takes one argument called side and returns the area of a regular hexagon given the length of the side. Show that the function works in a worksheet by inserting the formula somewhere.
. Write a function in JAVA called shorten that is defined in the class P8 and...
. Write a function in JAVA called shorten that is defined in the class P8 and shortens each element of an array of strings. Every string with more than two characters is cut down to its first two characters. For example, a program that uses the function shorten follows. public class P8 { public static void main(String args[]) { String x[] = {"CSCI", "1", "11", "Queens", "College", "CUNY"}; shorten(x); for (int i = 0; i < 6; i++) System.out.print(x[i] +...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C)...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C) that converts temperature in degrees F to temperature in degrees C. Use the function to solve the following problem. The change in the length of an object, ∆L, due to a change in the temperature, ∆T, is given by: ∆L = αL∆T, where a is the coefficient of thermal expansion. Determine the change in the area of a rectangular(4.5 m by 2.25m) aluminum (α=23·10-61/˚C)...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
In C++ Write a function called findBestSimScore that takes a genome and a sequence and returns...
In C++ Write a function called findBestSimScore that takes a genome and a sequence and returns the highest similarity score found in the genome as a double. Note: the term genome refers to the string that represents the complete set of genes in an organism, and sequence to refer to some substring or sub-sequence in the genome. Your function MUST be named findBestSimScore Your function should take two parameters in this order: a string parameter for the genome (complete set...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT