Hi just wondering if anyone can advise why this is not working and offer a solution, I am new to java. Thanks in advance for any help.
Print Pattern Feature
The “print pattern” feature should function as follows:
The user should be prompted to enter the following input values:
! the number of rows in the pattern to be printed
! and the actual character to be printed in the pattern
The feature should then proceed to print a triangular pattern of the specified character
based on the number of rows specified by the user as follows:
number of rows: 3
character to be printed: ‘X’
Output:
X
X X
X X X
Note that there is a space after each character that was printed.
The pattern should be printed using a nested loop which prints the characters in the
pattern one at a time (in the inner loop) – marks will be deducted from this section for
hard-coding pattern output in any way.
java
view plainprint?
1. package Programming1;
2. import java.io.BufferedReader;
3. import java.io.IOException;
4. import java.io.InputStreamReader;
5.
6.
7.
8. public class PrintNumberPattern
9. {
10. //-----------------------------------------------------------------
11. // Prints a triangle shape using asterisk (star) characters.
12. //-----------------------------------------------------------------
13.
14. public static void main (String[] args)
15. {
16. BufferedReader stdin = new BufferedReader(new InputStreamReader(
17. System.in));
18. int row = 0;
19. int numberOfLines = 0;
20.
21. // Get integer input
22. System.out.println( " Please enter number of rows in integer type ");
23. try {
24. String MAX_ROWS = stdin.readLine();
25. } catch (IOException e) {
26.
27. e.printStackTrace();
28. }
29.
30. BufferedReader charInput = new BufferedReader(new InputStreamReader(
31. System.in));
32.
33. // Get char input
34. System.out.println(" Please enter a character to be printed ");
35. try {
36. char MAX_ROWS = charInput.readLine().charAt(0);
37. } catch (IOException e) {
38.
39. e.printStackTrace();
40. }
41.
42. int MAX_ROWS = Integer.parseInt(args[0]);
43. for (int i = 1; i <= MAX_ROWS; i++)
44. {
45. for (int star = 1; star <= row; star++)
46. System.out.print ("*");
47.
48. System.out.println();
49. }
50. }
51. }