For this Question: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P.......A........H.......N
..A..P....L....S....I...I....G
....Y.........I........R
And then read line by line: PAHNAPLSIIGYIR
Write the code that will take a string and make this conversion given a number of rows.The first line of input contains an integer denoting the number of rows n.
The second line contains a string denoting the given string.

Constraints:
1<= Length of string <= 1000
1 < = n < = 10Output the converted zigzag string in a single line.Sample Input:
2
ABCD

Sample Output:
ACBD

A....C
...B....D
and hence the answer would be ACBD., I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {


					BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
					  	int n=Integer.parseInt(br.readLine());


					String str=br.readLine();


					int initial;
					if(n==1){
						initial=1;
					}else{
						initial=2*(n-1);
					}
					int pos1=initial;
					int pos2=0;
					int rem=n;
					boolean flag=true;

					for(int i=0;i<n;i++){

						for(int j=i;j<str.length();){
						System.out.print(str.charAt(j));

							if(pos2==0 || pos1==0){
								j+=pos1+pos2;
							}else{

								if(flag){
									j+=pos1;
								}else{
									j+=pos2;
								}
								flag=!flag;
							}

						}
						rem--;

						pos1=2*(rem-1);
						pos2=initial-pos1;

						flag=true;
					}


	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?