Question

In: Computer Science

Problem General Statement: Read in a letter and a number. The number indicates how big the...

Problem

General Statement: Read in a letter and a number. The number indicates how big the letter triangle should be. The number indicating the size of the triangle will have a range from 0 to 250. num>=0 and num<=250

Input: The first number indicates the number of data sets to follow. Each data set will contain one letter and one number. All letter input will be uppercase.

Data File : pr36.dat

Output: Output the letter triangle specified.

Helpful Hints / Assumptions: The letters must wrap around from Z to A. If you start with Z and have to print 5 levels, you must wrap around and start with A after the Z level is complete.

Sample Input :

3

5 A

3 Z

4 C

Sample Output :

A

BB

CCC

DDDD

EEEEE

Z

AA

BBB

C

DD

EEE

FFFF

Solutions

Expert Solution

Pattern.java

import java.io.File;
import java.util.Scanner;


public class Pattern {
   static char letters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
   public static void main(String[] args) {
       try {
           //reading input file
File file = new File("pr36.dat");
Scanner input = new Scanner(file);
int n = Integer.parseInt(input.nextLine());
for(int i=0;i<n;i++){
String data[] = input.nextLine().split(" ");
int num = Integer.parseInt(data[0]);
char letter = data[1].charAt(0);
//reading number and letter to print
printPattern(num,letter);
}
input.close();
} catch (Exception ex) {
ex.printStackTrace();
}
   }

   private static void printPattern(int num, char letter) {
       //getting index from letters array based on characters
       int index = (int)letter-65;
       for(int i=0;i<num;i++){
           for(int j=0;j<i+1;j++){
               //printing character that many times
               System.out.print(letters[index]);
           }
           //this is to iterate if Z came then make it as A
           index++;
           if(index == 26){
               index = 0;
           }
           System.out.println();
       }
   }
}
pr36.dat

3
5 A
3 Z
4 C


Related Solutions

Select the letter for which the statement indicates either (1) a purpose of, (2) a reason...
Select the letter for which the statement indicates either (1) a purpose of, (2) a reason for, or (3) a risk of this: Speculation on a price increase in the underlying security. options: call buying put buying uncovered call writer covered call writer Select the letter for which the statement indicates either (1) a purpose of, (2) a reason for, or (3) a risk of this: Risks loss of the entire premium if the price of the underlying security falls....
Please read the statement, identify the problem that a MNC would face in operating in a...
Please read the statement, identify the problem that a MNC would face in operating in a global environment and make recommendations to remedy the problem Diversification is possibly the best technique for reducing the problems associated with international transactions. Provide one example each of international financial diversification and international operational diversification and explain how the action reduces risk.
Please read the statement, identify the problem that a MNC would face in operating in a...
Please read the statement, identify the problem that a MNC would face in operating in a global environment and make recommendations to remedy the problem The Describe the two methods for the translation of foreign subsidiary financial statements into the parent company's consolidated statements. Identify when each technique should be used and the major advantage(s) of each.
Please read the statement, identify the problem that a MNC would face in operating in a...
Please read the statement, identify the problem that a MNC would face in operating in a global environment and make recommendations to remedy the problem There are as many different approaches to foreign exchange transaction exposure management as there are firms and no real consensus exists regarding the best approach. List and discuss three different exposures you can hedge and three different types of hedges.
How can an employer meet the spirit and letter of the General Duty Clause? What role...
How can an employer meet the spirit and letter of the General Duty Clause? What role does the level of risk play in the degree of effort that an employer might invest in their decision to either eliminate or mitigate (manage) the hazard?
Problem Statement You are required to read in a list of stocks from a text file...
Problem Statement You are required to read in a list of stocks from a text file “stocks.txt” and write the sum and average of the stocks’ prices, the name of the stock that has the highest price, and the name of the stock that has the lowest price to an output file. The minimal number of stocks is 30 and maximal number of stocks in the input file is 50. You can download a input file “stocks.txt” from Canvas. When...
perform each of the following steps: a) Read the problem statement. b) Formulate the algorithm using...
perform each of the following steps: a) Read the problem statement. b) Formulate the algorithm using pseudocode and top-down, stepwise refinement. c) Define the algorithm in JavaScript. d) Test, debug and execute the JavaScript. e) Process three complete sets of data. Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script...
Part A: Simple array algorithms With your buddy, read through this problem statement. Be sure to...
Part A: Simple array algorithms With your buddy, read through this problem statement. Be sure to read the Javadoc comments for the evenOdd method. Scribe: What is the return type of the evenOdd method? Scribe: How do you create an int array that can hold two numbers? The problem of coding the evenOdd method decomposes into three simpler problems. Scribe: What are they? Scribe: Which algorithm in section 7.3 of your textbook will be helpful? Scribe: Assuming that you have...
Read the article, “Big Data in Big Companies” (written by Thomas Davenport and Jill Dyche) from...
Read the article, “Big Data in Big Companies” (written by Thomas Davenport and Jill Dyche) from the International Institute from Analytics. Comment on the role of business analytics in business today. ( Answer Needs to be at least 150 words)
Problem 6.21 A 5000kg truck is parked on a 12? slope. Part A How big is...
Problem 6.21 A 5000kg truck is parked on a 12? slope. Part A How big is the friction force on the truck? The coefficient of static friction between the tires and the road is 0.90.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT