## Interview Question

Java Developer Interview

-

# take input from user...3,5,7 etc and draw a pattern if input is 3 then *** *** * * *** * * * if input is 5 then ***** ***** * * * * * * ***** * * * * *

1

code for c language #include #include int main() {int n=7,i,j,l,k,m; for(i=1;i<=n;i++) printf("*"); printf(" "); for(i=1;i<=n;i++) printf("*"); printf("\n"); for(j=1;j<=n-2;j++) { for(k=1;k<=n-1;k++) printf(" "); printf("*"); printf(" "); printf("*"); printf("\n"); } for(i=1;i<=n-1;i++) printf(" "); for(i=1;i<=n;i++){ printf("*");} printf("\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf(" "); printf("*"); printf("\n"); } return 0; }

shubham singh on

2

/* if input is 3 then *** *** * * *** * * * if input is 5 then ***** ***** * * * * * * ***** * * * * * */ import java.util.Scanner; public class Pattern3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); for(int i=1; i<=2; i++){ for(int j=1; j<=n; j++){ System.out.print("*"); }System.out.print(" "); }System.out.println(); for(int i=1; i<=n-2; i++){ for(int j=1; j<=n-1; j++){ System.out.print(" "); }System.out.println("* *"); } for(int i=1; i<=(n+1)/2; i++){ System.out.print(" "); } for(int i=1; i<=n; i++){ System.out.print("*"); }System.out.println(); for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ System.out.print(" "); }System.out.println("*"); } sc.close(); } }

Umang on

1

check this import java.util.Scanner; public class MyClass { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<2;i++){ for(int j=0;j

nickey on

0

#must look for the spaces and loops# def fun(n): print("*"*n+" "+"*"*n) for x in range(0,n-2): for y in range(0,n-2): print(" ",end="") print("*"+" "+"*") print(" "*(n-1)+"*"*n,end="") print() for x in range(0,n): print(" "*(n-1),"*") fun(3) fun(5) fun(7)

Ritesh Kumar on

0

follow codeforwin.com for practice on patterns

Anonymous on

0

import java.util.*; class Pattern{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=2;i++){ for(int j=1;j<=n;j++){ System.out.print("*"); } System.out.print(" "); } System.out.println(); for(int i=1;i<=n-2;i++){ for(int j=1;j<=n-1;j++){ System.out.print(" "); } System.out.print("* *"); System.out.println(); } for(int i=0;i<=n-i;i++){ System.out.print(" "); } for(int j=1;j<=n;j++){ System.out.print("*"); } System.out.println(); for(int j=1;j<=n;j++){ for(int i=0;i

Gulrez on

0

import java.util.Scanner; class New2 { public static void main(String ... args) { Scanner sc =new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=2;i++) { for(int j=1;j<=n;j++) System.out.print("*"); System.out.print(" "); } System.out.println(""); for(int j=1;j<=n-2;j++){ for(int i=1;i<=n-1;i++) System.out.print(" "); System.out.print("* *"); System.out.println(""); } for(int i=1;i<=n-1;i++) System.out.print(" "); for(int i=1;i<=n;i++) System.out.print("*"); System.out.println(""); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) System.out.print(" "); System.out.println("*"); } }}

Sarthak Tomar on

0

#include int main() { int n,i,j,l,k; scanf("%d",&n); for(i=1;i<=2;i++) { for(j=1;j<=n;j++) { printf("*"); } printf(" "); } printf("\n"); for(j=1;j

perfect code on

0

import java.util.Scanner; public class MyClass { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<2;i++){ for(int j=0;j

nickey on