KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

Exam
 xam
  am
   m

Java

Java Nested for Loops

ICSE

16 Likes

Answer

public class KboatPattern
{
    public static void main(String args[]) {
        String str = "Exam";
        int n = str.length() - 1;
        
        for (int i = n, x = 0; i >= 0; i--, x++) {
            
            for (int j = n; j > i; j--)
                System.out.print(" ");
                
            for (int k = x; k <= n; k++)
                System.out.print(str.charAt(k));
                
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program in Java to display the following pattern: Exam xam am m

Answered By

11 Likes