write a menu driven program to display the pattern as per user's choice.
Pattern 1::
1
12
123
1234
12345
...
...
Pattern 2::
12345
1234
123
12
1.
.
..
For an incorrect option , an appropriate error message should be display.
Please fast
Answers
the answer is :
import java.io.*;
class pattern3
{
void main() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter:\n1.for\n1\n12\n123\n1234\n12345\npattern\n2.for\n12345\n1234\n123\n12\n1\npattern");
int n=Integer.parseInt(br.readLine());
System.out.println("enter no of lines ");
int line=Integer.parseInt(br.readLine());
switch(n)
{
case 1:
for(int i=1;i<=line;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
break;
case 2:
for(int i=line;i>0;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
break;
}
}
}
Answer:
it is correct answer thanks