+ 1

Help me doing this pattern as soon as possible

abcdedcba abcd dcba abc cba ab ba a a

15th Mar 2017, 1:14 PM
Aman Agarwal
Aman Agarwal - avatar
2 Réponses
+ 2
here is the code : public static void printFormula(String s , int counter ){ if(s.length() == 0){ return; } for(int k = 0 ; k < s.length() ;k++){ System.out.print(s.toCharArray()[k]); } for(int i = 0; i < counter ; i++){ System.out.print(" "); } for(int k = s.length()-1; k > -1 ;--k){ System.out.print(s.toCharArray()[k]); } System.out.println(""); print(s.substring(0, s.length()-1), ++counter); } public static void main(String[] args) { printFormula("abcde" , 0); }
15th Mar 2017, 2:35 PM
ahmed khattab
ahmed khattab - avatar
+ 2
System.out.print("abcdedcba\nabcd dcba\nabc cba\nab ba\na a"); If You need quicker method then use machine code:D
15th Mar 2017, 3:07 PM
Michał Bujakowski
Michał Bujakowski - avatar