Friday, January 23, 2015

Java Code for Number Pattern 3


In the program the following star pattern will be printed.

1
12
123
1234
12345


The program is shown below :

import java.util.*;
class pattern8
{
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
int n;
System.out.println("Enter the number of rows");
n=scr.nextInt();

for(int i=1;i<=n;++i)
{
for(int j=1;j<=i;++j)
{
System.out.print(j);
}
System.out.println();
}
}
}


OUTPUT

C:\Users\Ravi\Desktop\ravi>javac pattern8.java
C:\Users\Ravi\Desktop\ravi>java pattern8

Enter the number of rows
6

1
12
123
1234
12345
123456



No comments:

Post a Comment