Pattern 5
1
2 3
4 5 6
7 8 9 10
import java.io.*;
class Patterns6{
public static void main(String args[])throws IOException{
//declare all the variables at the beginning
int n,i,j,c;
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter the number of rows : ");
n = Integer.parseInt(br.readLine());
c = 1;
//loop to generate the number of terms in the series
for(i = 1; i <= n; i++){
for(j = 1; j <= i; j++){
System.out.print(c+" ");
c++;
}//end of inner loop
System.out.println();
}//end of outer loop
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments