public class Ex15 { public static void printDesign() { for (int line = 1; line <= 5; line++) { int nHyphens = 6-line; for (int h = 0; h < nHyphens; h++) { System.out.print("-"); } int number = 2 * line - 1; for (int n = 0; n < number; n++) { System.out.print(number); } for (int h = 0; h < nHyphens; h++) { System.out.print("-"); } System.out.println(); } } public static void main(String[] args) { printDesign(); } } The code below is better design. System output (print() statements) ideally should happen in one place only, rather than scattered throughout your program. This helps immensely when you have to debug your code. Methods should return data (numbers, text, objects, etc.) public class Ex15 { public static String printDesign() { String str = ""; for (int line = 1; line <= 5; line++) { int nHyphens = 6-line; for (int h = 0; h < nHyphens; h++) { str += "-"; } int number = 2 * line - 1; for (int n = 0; n < number; n++) { str += number; } for (int h = 0; h < nHyphens; h++) { str += "-"; } str += "\n"; } return str; } public static void main(String[] args) { String str = printDesign(); System.out.print(str); } }