Wednesday, 14 October 2020

Print the following pattern.

a1 
a2 b3 
a4 b5 c6 
a7 b8 c9 d10






import java.io.*;

public class ass4

{

public void main() throws IOException

{

InputStreamReader in = new InputStreamReader(System.in);

BufferedReader br =new BufferedReader(in);

int r,c,sum=1,s;

System.out.println("Enter the no of rows you want");

int n=Integer.parseInt(br.readLine());

for(r=1;r<=n;r++)

{

sum+=r;

s=sum-r;

for(c=1;c<=r;c++)

{


System.out.print((char)(96+c)+""+s+" ");

s++;

}

System.out.println();

}

}

}




Output:

Enter the no of rows you want

4


a1 

a2 b3 

a4 b5 c6 

a7 b8 c9 d10

No comments:

Post a Comment