ClicQA interview question

Write a java code for pattern: