0

Can anyone tell me why it Is not giving satisfactory output?

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

10th May 2021, 4:20 PM
Atul
Atul - avatar
2 Antworten
0
Problem in adding spaces in 2nd loop.... Try again.. and reply.. Start from length-1 to >a and use a++ only.. instead of adding 2. Hope you solve it..! edit: in case , you did not get it right after your tried again ... then only try this .. for(int k=n.length()-1;k>a;k--){ System. out. print(" ");
11th May 2021, 7:02 PM
Jayakrishna 🇮🇳
0
I have got the answer of it earlier
12th May 2021, 8:49 AM
Atul
Atul - avatar