QA InfoTech Interview Question

Use single loop instead of two loops to print a K-shaped pattern.

Interview Answers

Anonymous

Sep 30, 2019

public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0,j=0; i=n && j==0 || j==(i-n)+1){ System.out.print("* "); j++; } else{ System.out.print(" "); j++; } }else{ j=0; i++; System.out.println(); } } }

1

Anonymous

Sep 30, 2019

edited..!! Screenshot 2019-09-30 at 8.14.07 PM

1

Anonymous

Mar 25, 2019

Question of java is output Or theory

2