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?
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
HOW TO: 1. Write the SQL statement to show workers with names that have the letter...
HOW TO: 1. Write the SQL statement to show workers with names that have the letter ? before the last character. 2. Write the SQL statement to show all staff where the 2nd letter of their last names is ′?′ 3. Write the SQL statement to show all staff where the 1stletter of their first names is ′?′ and 3rd letter ′ℎ' DROP TABLE IF EXISTS staff; CREATE TABLE staff ( staffNo VARCHAR(4) UNIQUE, fName VARCHAR(16), lName VARCHAR(16), position VARCHAR(16),...
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...
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the...
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the information from a file into a list and then display the list to the screen. Add your name. Sort the list by id. Print the list again CODE: Use the provided disneyin2.txt file. Do not hard code the file name; get file name from user. Use the struct below struct student { char firstnm[20], lastnm[20]; int id, grade; }; You are to create a...
12.) What is a virtual team? 13.) Describe, in general, how the Big 5 relates to...
12.) What is a virtual team? 13.) Describe, in general, how the Big 5 relates to leader effectiveness. 14.) How does a team differ from a group? 15.) How does a project team differ from a production team? 16.) In the input-process-output model of team effectiveness, describe the team inputs. Describe specifically how an I-O psychologist could be useful in one of the team inputs. 17.) In the input-process-output model of team effectiveness, describe the team processes. 18.) Dr. Rosopa...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT