Pergunta de entrevista da empresa WebKul

print the pattern for n=3 ***** *** * * *** for n=5 ******* ***** * *** *** * ***** and so on ................ code should only work for odd inputs.

Resposta da entrevista

Sigiloso

15 de out. de 2018

import java.util.Scanner; public class webkul1 { public static void main(String [] args) { Scanner s= new Scanner(System.in); int num=s.nextInt(); int next=num; s.nextLine(); int half=(num+1)/2; int lspace=half; while(true) { ++next; if(next%2!=0) break; } while(lspace>0) { System.out.print(" "); lspace--; } for(int i=0;i=1;i--) { for(int j=half;j>=i;j--) { System.out.print(" "); } for(int k=((2*i)-1);k>0;k--) { System.out.print("*"); } for(int p=1;p=((2*i)-1);k--) { System.out.print("*"); } System.out.println(); } s.close(); } }

1