Computer Science, asked by ary41, 1 year ago

in Java pattern based question when to print J and went to print I

Answers

Answered by Himanshu119820
1
Pattern 1 : Printing Floyd’s triangle pattern

Floyd’s triangle is a right-angled triangular array of natural numbers.

It is named after Robert Floyd.

It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

 

 

package com.topjavatutorial;

 

public class FloydTriangle {

 

    public static void main(String[] args) {

        int i, j, k = 1;

        for (i = 1; i <= 5; i++) {

            for (j = 1; j < i + 1; j++) {

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

            }

 

            System.out.println();

        }

    }

 

}

 

 

Pattern 2 : Printing Pascal’s triangle Pattern

Pascal’s triangle is a triangular array of the binomial coefficients.

It is named after Blaise Pascal.

The triangle may be constructed in the following manner: In row 0 (the topmost row), there is a unique nonzero entry 1. Each entry of each subsequent row is constructed by adding the number above and to the left with the number above and to the right, treating blank entries as 0.

             1            1   1          1   2   1        1   3   3   1      1   4   6   4   1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

 

 

package com.topjavatutorial;

 

public class PascalTriangle {

 

    public static void main(String[] args) {

 

        int n = 5;

 

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

            int number = 1;

            System.out.printf("%" + (n - i) * 2 + "s", "");

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

                System.out.printf("%4d", number);

                number = number * (i - j) / (j + 1);

            }

            System.out.println();

        }

 

    }

 

}

 

 

Pattern 3 : Diamond shape composed of Star(*)

    *    ***   ***** ******* ********* *******   *****    ***     *

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

 

 

package com.topjavatutorial;

 

public class DiamondPattern {

 

    public static void main(String[] args) {

        int number, i, k, count = 1;

        number = 5;

        count = number - 1;

        for (k = 1; k <= number; k++)

        {

            for (i = 1; i <= count; i++)

                System.out.print(" ");

            count--;

            for (i = 1; i <= 2 * k - 1; i++)

                System.out.print("*");

            System.out.println();

        }

        count = 1;

        for (k = 1; k <= number - 1; k++)

        {

            for (i = 1; i <= count; i++)

                System.out.print(" ");

            count++;

            for (i = 1; i <= 2 * (number - k) - 1; i++)

                System.out.print("*");

            System.out.println();

        }

    }

}

 

 

 

Pattern 4 : Diamond shape composed of Numbers

   1   212 32123 4321234 32123   212    1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

 

 

package com.topjavatutorial;

 

public class DiamondPattern {

 

    public static void main(String[] args) {

        for (int i = 1; i <= 4; i++)

        {

            int n = 4;

            for (int j = 1; j <= n - i; j++)

            {

                System.out.print(" ");

            }

            for (int k = i; k >= 1; k--)

            {

                System.out.print(k);

            }

            for (int l = 2; l <= i; l++)

            {

                System.out.print(l);

            }

            System.out.println();

        }

        for (int i = 3; i >= 1; i--)

        {

            int n = 3;

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

            {

                System.out.print(" ");

            }

            for (int k = i; k >= 1; k--)

            {

                System.out.print(k);

            }

            for (int l = 2; l <= i; l++)

            {

                System.out.print(l);

            }

            System.out.println();

        }

    

    }

}

 

 

 

Pattern 5 : Diamond shape composed of Alphabets

Enter a Char between A to Z : G       A      B B     C   C    D     D   E       E F         F G           G F         F   E       E    D     D     C   C      B B       A

please mark me as brainliest
and follow me
Answered by vannan2oo4
0

Answer:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvs

Explanation:

Similar questions