KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

bo
tt
le
s

Java

Java Nested for Loops

ICSE

6 Likes

Answer

public class KboatPattern
{
    public static void main(String args[]) {
        String str = "bottles";
        for (int i = 0; i < str.length(); i++) {
            System.out.print(str.charAt(i));
            if ( i % 2 != 0)
                System.out.println();
        }
    }
}

Output

BlueJ output of Write a program in Java to display the following pattern: bo tt le s

Answered By

3 Likes