Pattern with Zeros1

whats wrong in my code

Question

Pattern with Zeros

Take N (number of rows), print the following pattern (for N = 5)
1
2 2
3 0 3
4 0 0 4
5 0 0 0 5
Input Format:
Constraints:

0 < N < 100

Solution

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

Hi Donnaghai

Firstly, please send your code by pasting it in ide.codingblocks.com, saving it and then sending the link here. Secondly, you need to add tab after printing any value, as shown in the sample I/O too.

Made the required changes to your code.

import java.util.*;

public class Heap1 {

public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	for (int i = 1; i <= n; i++) {

		if (i > n / 2) {
			System.out.print(i + " ");
			for (int k = 1; k <= i - 2; k++) {
				System.out.print("0" + " ");
			}
			System.out.print(i);
		} else {
			for (int j = 1; j <= i; j++) {
				System.out.print(i + " ");
			}
		}
		System.out.println();
	}
}

}

Hi
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.