TO PRINRT THE FOLLOWING PATTERN
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15 16
ALGORITHM
Step-1 Start
Step-2 Take the limit value from the user.
Step-3 Initialization of the variables for different tasks.
Step-4 Run the loop for number of lines.
Step-5 Run another loop inside loop started in step-3 for printing
numbers.
Step-6 Print the numbers.
Step-7 Change the line
Step-8 Exit
PROGRAM
class pattern1
{
public static void main(int l)
{
int a,c,n=1;
for (a=1;a<=l;a++)
{
for (c=1;c<=a;c++)
{
System.out.print(n+"\t");
n++;
}
System.out.println();
}
}
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
a | Integer type | For running loop for Change the lines |
c | Integer type | For printing the numbers. |
l | Integer type | For taking the limit range. |
n | Integer type | Stores the numbers which has to be printed during the loop. |
INPUT/OUTPUT
INPUT | OUTPUT |
3 | 1 2 3 4 5 6 |
4 | 1 2 3 4 5 6 7 8 9 10 |
TO PRINT THE CHRISTMAS TREE OF ASTERIKS
*
* *
* * *
* * * *
* * * * *
* * * * * *
ALGORITHM
Step-1 Start
Step-2 Take limit for number of lines to be printed from the user.
Step-3 Initialization of variables.
Step-4 Run the loop for printing number of lines.
Step-5 Run the loop giving spaces.
Step-6 Printing of spaces.
Step-7 Run loop for printing the asterisk.
Step-8 Print the asterisk.
Step-9 Print the space between two asterisks (if required).
Step-10 Change the line.
Step-11 Exit
PROGRAM
class pattern2
{
public static void main(int n)
{
int a,b,c,k=n;
for (a=1;a<=n;a++)
{
for (b=1;b<=k;b++)
{
System.out.print(" ");
}
k--;
for (c=1;c<=a;c++)
{
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
}
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
n | Integer type | For storing the range for number of lines |
a | Integer type | For running loop for number of lines |
b | Integer type | For running loop for printing spaces |
c | Integer type | For running loop for printing of ‘*’ |
k | Integer type | For storing the value of variable n |
INPUT/OUTPUT-
INPUT | OUTPUT |
5 | * ** *** **** ***** |
6 | * ** *** **** ***** ****** |
TO PRINT THE FOLLOWING PATTERN
0
101
21012
3210123
432101234
ALGORITHM
Step-1 Start
Step-2 Take the number limit from the user.
Step-3 Initialization of variables.
Step-4 Run the loop for number of lines till one more time than the user entered.
Step-5 Run the loop for giving the spaces.
Step-6 Print the spaces.
Step-7 Run the loop for printing the numbers of the left hand side.
Step-8 Print the numbers.
Step-9 Run the loop for printing the numbers of the right hand side.
Step-10 Print the numbers.
Step-11 Change the line.
Step-12 Exit
PROGRAM
class pattern3
{
public static void main(int n)
{
int a,b,c,d,e=0,k=n;
for (a=0;a<n+1;a++)
{
for (b=0;b<k;b++)
{
System.out.print (" ");
}
k--;
for (c=e;c>=0;c--)
{
System.out.print (c);
}
for (d=1;d<a+1;d++)
{
System.out.print (d);
}
e++;
System.out.println();
}
}
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
n | Integer type | For storing the number limit |
a | Integer type | For running loop for number of lines |
b | Integer type | For running loop for printing spaces |
c | Integer type | For running loop, for printing the numbers of left hand side |
d | Integer type | For running loop, for printing the numbers of right hand side |
e | Integer type | Counter variable for printing the numbers of left hand side |
k | Integer type | For storing the value of variable n |
INPUT/OUTPUT
INPUT | OUTPUT |
9 | 0 101 21012 3210123 432101234 54321012345 6543210123456 765432101234567 87654321012345678 9876543210123456789 |
10 | 0 101 21012 3210123 432101234 54321012345 6543210123456 765432101234567 87654321012345678 9876543210123456789 10987654321012345678910 |
TO PRINT ANY CHARACTER IN ‘R’ FORMATION ACCORDING TO THE GIVEN NUMBER OF TIMES
@ @ @
@ @
@ @
@ @ @
@ @
@ @
@ @
ALGORITHM-
Step-1 Start
Step-2 Take a character for printing and limit for printing it no. of times.
Step-3 Initialization of variables.
Step-4 Run the loop for printing the no. of lines for square.
Step-5 If loop variable is equal to first value (i.e. 0) or last value {i.e. (limit-1)}
Then proceed to step 6 else to step 7.
Step-6 Run the loop for printing the first and last line of square only.
Step-7 Print the character only.
Step-8 Run the loop for giving the spaces inside the square.
Step-9 Print the character.
Step-10 Change the line.
Step-11 Run the loop for the lambda formation (present below the square).
Step-12 Print the character.
Step-13 Run the loop for printing the spaces.
Step-14 Print the spaces in ascending order.
Step-15 Print the character outside the space loop once again.
Step-16 Change the line.
Step-17 Exit
PROGRAM
class pattern4
{
public static void main(char ch,int n)
{
int a,b,c=0;
for (a=0;a<n;a++)
{
if (a==0||a==(n-1))
{
for (b=0;b<n;b++)
{
System.out.print (ch);
}
}
else
{
System.out.print(ch);
for (b=0;b<(n-2);b++)
{
System.out.print (" ");
}
System.out.print(ch);
}
System.out.println();
}
for (a=0;a<n;a++,c++)
{
System.out.print (ch);
for (b=0;b<c;b++)
{
System.out.print(" ");
}
System.out.print(ch);
System.out.println();
}
}
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
a | Integer type | 1. For running the loop to print the no. of lines in square formation. 2. For printing the no. of lines in lambda formation. |
b | Integer type | 1. For printing the no. of spaces inside the square. 2. For printing the no. of spaces in lambda formation |
c | Integer type | Counter variable used for giving spaces in lambda formation. |
n | Integer type | For storing the limit value entered by the user |
INPUT/OUTPUT-
INPUT | OUTPUT | |
CHARACTER | LIMIT | |
A | 3 | AAA A A AAA AA A A A A |
& | 4 | &&&& & & & & &&&& && & & & & & & |
TO PRINT THE FOLLOWING PATTERN
123
12
1
12
123
ALGORITHM
Step-1 Start
Step-2 Take the number limit from the user.
Step-3 Initialization of variables.
FOR UPPER PART-
Step-4 Run the loop for printing number of lines.
Step-5 Run the loop for giving spaces.
Step-6 Print the spaces.
Step-7 Run the loop for printing the numbers.
Step-8 Print the numbers.
Step-9 Increment of a counter variable.
Step-10 Change the line.
Step-11 Condition for checking that whether the counter variable is equal to 2 or not. If yes then break the main loop else value of counter variable will become 0 again.
FOR LOWER PART-
Step-12 Run the loop for printing the no. of lines.
Step-13 Run the loop for printing no. of spaces.
Step-14 Print the spaces.
Step-15 Run the loop for printing the numbers.
Step-16 Print the numbers.
Step-17 Change the line.
Step-18 Exit
PROGRAM
class pattern6
{
public static void main(int n)
{
int a,b,s,c,q=n,f,j=0,k=n,i=0,v=1;
for (a=1;a<=n;a++)
{
for (b=0;b<=j;b++)
{
System.out.print(" ");
}
j++;
for (c=1;c<=k;c++)
{
System.out.print(c);
i++;
}
k--;
System.out.println();
if(i==2)
break;
else
i=0;
}
for (a=0;a<n;a++)
{
for (s=0;s<q;s++)
{
System.out.print(" ");
}
for (f=1;f<=v;f++)
{
System.out.print(f);
}
q--;
v++;
System.out.println();
}
}
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
a | Integer type | 1. For running the loop to print the no. of lines in upper part. 2. For printing the no. of lines in lower part. |
b | Integer type | For running the loop to print the no. of spaces in the upper part. |
c | Integer type | For running the loop to print the numbers of the upper part. |
f | Integer type | For running the loop to print the numbers of the lower part. |
s | Integer type | For running the loop to print the numbers of spaces in the lower part. |
q | Integer type | For storing the value of variable ‘n’ and used as a final limit in the loop of spaces of lower part. |
j | Integer type | A counter variable used as final limit in loop of space of upper part. |
k | Integer type | For storing the value of variable ‘n’ and used as a final limit in the loop for printing number of upper part. |
i | Integer type | A counter variable for limiting the printing of the numbers of upper part till ‘12’. |
v | Integer type | Loop variable used as a final limit in the printing of the numbers of the lower part. |
n | Integer type | For storing the limit value entered by the user |
INPUT/OUTPUT
INPUT | OUTPUT |
5 | 12345 1234 123 12 1 12 123 1234 12345 |
8 | 12345678 1234567 123456 12345 1234 123 12 1 12 123 1234 12345 123456 1234567 12345678 |
TO PRINT TO FOLLOWING PATTERN
1
121
12321
1234321
ALGORITHM
Step-1 Start
Step-2 Take the limiting value from the user.
Step-3 Initialization of variables.
Step-4 Run the loop for printing the no. of lines.
Step-5 Run the loop for printing the numbers of spaces.
Step-6 Print the spaces.
Step-7 Run the loop for printing the numbers of the left hand side.
Step-8 Print the numbers.
Step-9 Run the loop for printing the numbers of the right hand side.
Step-10 Print the numbers.
Step-11 Change the line.
Step-12 Exit
PROGRAM
class pattern7
{
public static void main(int n)
{
int a,b,c,d,k=n;
for (a=1;a<=n;a++)
{
for (b=1;b<k;b++)
{
System.out.print (" ");
}
k--;
for (c=1;c<=a;c++)
{
System.out.print (c);
}
for (d=a-1;d>=1;d--)
{
System.out.print(d);
}
System.out.println();
} }
}
VARIABLE DESCRIPTION-
VARIABLE USED | DATATYPE | DESCRIPTION |
n | Integer type | For storing the limiting value |
a | Integer type | For running the loop to print the no. of lines. |
b | Integer type | For running the loop to print the no. of spaces. |
c | Integer type | For running the loop to print the numbers of the left hand side. |
d | Integer type | For running the loop to print the numbers of the right hand side. |
k | Integer type | For storing the value of variable ‘n’ and use it as a counter variable. |
INPUT/OUTPUT
INPUT | OUTPUT |
5 | 1 121 12321 1234321 123454321 |
hi plz let me know how to print A symbol with asteriks
ReplyDeleteHey,plzz...Tell me that is there any app where we can type the program and can get the variable description
ReplyDelete