View the step-by-step solution to:

COM S 207 Triangle Pattern Write a program that reads in lines from the input. Each line has a single integer followed by a single character. The...

This is java programming. Due date is Tomorrow.

Thank you

COM S 207 Triangle Pattern Write a program that reads in lines from the input. Each line has a single integer followed by a single character . The objective is to print a triangle pattern using the input character. The first integer represents the number of rows of the triangle. Input values will contain only integers greater than or equal to 1 and less than or equal to 50. Input The format of an input line is noRows char The first is an integer (and can be read using nextInt()). The last one is a single character (like *) and can be read using next() as a String and then using charAt(0) to get at the first character. Output For each line of input, a triangular pattern is printed consisting of several rows. If the no of rows is less than or equal to zero or more than 50, the program prints out an error statement as shown in the sample output. Sample Input 2 * -1 ' 10 = Sample Output * ** error in input = == === ==== ===== ====== ======= ======== ========= ========== HINT 1. use in.next().charAt(0) to get the character. 2. don’t forget to discard the rest of the input line using in.nextLine() if you are using in.hasNextLine() to check if there is a next line. 3. You will need two loops for this one as well.
COM S 207 ThreeNumbersM This problem is almost exactly like 006 ThreeNumbers problem, except that here you need to use a method to do the calculations. Declare a method named calcSumProdAvg as follows: private static void calcSumProdAvg(double d1, double d2, double d3){ // write your code for doing the calculations AND printing here. } In the main method, do all the reading of the lines and doubles. Call this method from the main method to calculate the sum, product, and average and to print them out. Write a program that reads in three integers and prints out their sum and product and average Input The input will be one or more lines of numbers that have been typed in by the user. Each line is to have exactly three real numbers. Output The output will have for each line, the numbers that had been read in separated by a single space followed by their sum, product, and average separated by a space. Each number is to be printed using "%.2e" format (see hint below). Sample Input 1 2 3 1.1 2.2 3.3 Sample Output 1.00e+00 2.00e+00 3.00e+00 6.00e+00 6.00e+00 2.00e+00 1.10e+00 2.20e+00 3.30e+00 6.60e+00 7.99e+00 2.20e+00
Page 2 of 2 pages HINT Here use in.nextDouble() to read a number. After reading three doubles, use in.nextLine() – so that you discard the rest of the "white spaces". To print two numbers num1 and num2 using %.2e format, I would use System.out. printf ("%.2e %.2e\n", num1, num2); The \n is used to make sure it prints a newline character. The printf method can be found in your textbook – section 2.5.5 Formatted Output
COM S 207 Rectangle Patterns Write a program that reads in lines from the input. Each line has two integer values followed by a single character . The objective is to print a rectangle pattern using the input pattern. The first integer represents the number of rows and the second integer represents the number of columns. Input The format of an input line is noRows noCols char The first two are integers (and can be read using nextInt()). The last one is a single character (like *) and can be read using next() as a String and then using charAt(0) to get at the first character. Output For each line of input, a rectangular pattern is printed consisting of several rows. If the no of rows or cols is less than or equal to zero or more than 50, the program prints out an error statement as shown in the sample output. Sample Input 2 2 , 2 51 + 10 10 = 0 11 * Sample Output ,, ,, error in input ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== error in input HINT 1. use in.next().charAt(0) to get the character. 2. don’t forget to discard the rest of the input line using in.nextLine() if you are using in.hasNextLine() to check if there is a next line. 3. You will need TWO loops to print each rectangle.

View the full answer
load.rar - Preview not available

View the full answer

View the full answer

View the full answer

View the full answer

View the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
• -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents