samedi 23 avril 2022

Program using nested for loops to print string pattern is not working. What code do I use for the loop to make it print the required pattern?

This is the pattern I'm trying to print: Required pattern

This is the code I have written:

                    for(int c = s.length; c >= 1; c--)
                    {
                        for (int d = c; d >= 0; d--)
                        {
                            char y = s.charAt(d);
                            System.out.print(y);
                        }
                        System.out.println();
                    }

Sadly, the program isn't compiling. What do I change in this code to make it print the required pattern?

Aucun commentaire:

Enregistrer un commentaire