Computer Science, asked by ankit207596, 9 months ago

I want the answer in bluej language.
Create a class to print the following output by using method overloading. Write main

function also.

i) void pattern (int a, int b)- To draw the following pattern from a to b

sample input: a=1 and b=10

sample output:

1

2 3

4 5 6

7 8 9 10

ii) void pattern (char c) – To draw the following pattern with a symbol.

Sample input: $

Sample output:

$

$$

$$$

$$$$​

Answers

Answered by Oreki
2

public class Triangles {

void pattern(char c) {

for (int i = 0; i < 5; i++) {

for (int j = 0; j <= i; j++)

System.out.print(c + " ");

System.out.println( );

}

}

void pattern(int a, int b) {

for (int i = 0; a <= b; i++) {

for (int j = 0; j <= i; j++, a++)

System.out.print(a + " ");

System.out.println( );

}

}

public static void main(String[ ] args) {

Triangles triangle = new Triangles( );

triangle.pattern('#');

triangle.pattern(2, 11);

}

}

Similar questions