you are given an integer N,print N+1 lines in a following manner
case 1: N=3 then the pattern would be
case 2: N=4 then the pattern would be
Answers
Answered by
3
NN
N1
N2
N3
HERE INTEGER N+1
N1
N2
N3
HERE INTEGER N+1
Answered by
2
The program in JAVA is written below :
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter value of n : ");
int n = sc.nextInt( );
int row = 0;
int column = 0;
if(n%2 == 0) {
row = n + 1 ;
column = n + 1 ;
}
else {
row = n+1;
column = n;
}
int arr [ ] [ ] = new int [row] [column] ;
int count = 1 ;
int half = n / 2 ;
for ( int i = 0 ; i < row ; i++ ) {
for ( int j = 0 ; j<column ; j++) {
if ( ( i > 0 && i < row ) && j == half) {
arr[ i ] [ j ] = count;
count++;
}
else {
arr [ i ] [ j ] = n;
}
}
}
for( int i = 0; i < row ; i++) {
for( int j=0 ; j < column ; j++) {
System.out.print ( arr [ i ] [ j ] );
}
System . out . println( );
}
sc.close( );
}
Similar questions