0

How to print this pattern?

e e de ed cde edc bcde edcb abcdedcba

14th Feb 2019, 3:54 PM
Adam Mahendra
Adam Mahendra - avatar
3 ответов
+ 6
Well it's been more than a week with no follow up, you probably have solved it anyway, I'll just post what I did here, good training for me. public class VPattern { public static void main(String[] args) { int n = 5; // 5 rows int width = n * 2 - 1, last = width - 1; char letter = 'a'; for(int x = 1; n != 0; n--, x++) { for(int c = 0, v = n - 1; c < width; c++) { if(c < x) { System.out.printf("%c", letter + v++); } else if(c > last - x) { if(n == 1 && c == x) --v; System.out.printf("%c", letter + --v); } else { System.out.print(" "); } } System.out.println(); } } }
23rd Feb 2019, 2:51 PM
Ipang
+ 2
Please share your attempt first
14th Feb 2019, 4:10 PM
Seniru
Seniru - avatar
0
package com.javainterviewpoint; public class Pattern1 { public static void main(String[] args) { int alphabet = 65; System.out.println("** Printing the pattern... **"); for (int i = 0; i <= 5; i++) { for (int j = 0; j <= i; j++) { System.out.print((char) (alphabet + j) + " "); } System.out.println(); } } } Only can make this, i really need to know about how to print that pattern
14th Feb 2019, 4:13 PM
Adam Mahendra
Adam Mahendra - avatar