0% found this document useful (0 votes)
1K views

Pattern Programs in Java

The document contains 3 Java programs that print out number/star patterns. The first program prints an ascending star pattern, the second prints a descending star pattern, and the third prints a descending number pattern from the given number down to 1. Each program uses a for loop within a for loop to iterate through the rows and columns to print out the pattern.

Uploaded by

vikki chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Pattern Programs in Java

The document contains 3 Java programs that print out number/star patterns. The first program prints an ascending star pattern, the second prints a descending star pattern, and the third prints a descending number pattern from the given number down to 1. Each program uses a for loop within a for loop to iterate through the rows and columns to print out the pattern.

Uploaded by

vikki chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pattern programs in java

/* write a program to print this pattern

*
**
***
****
*****
*/

import java.util.*;

class x
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.print("enter a number to print pattern : ");
int n=sc.nextInt();
for(int a=1;a<=n;a++)
{
for(int i=1;i<=a;i++)
{
System.out.print("*"+" ");
}
System.out.println();
}
}
}
/* write a program to print this pattern

*****
****
***
**
* */

import java.util.*;

class x
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.print("enter a number to print pattern : ");
int n=sc.nextInt();
for(int a=n;a>=1;a--)
{
for(int i=a;i>=1;i--)
{
System.out.print("*"+" ");
}
System.out.println();
}
}
}
/* write a program to print this pattern

12345
1234
123
12
1 */

import java.util.*;

class x
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.print("enter a number to print pattern : ");
int n=sc.nextInt();
for(int a=n;a>=1;a--)
{
for(int i=1;i<=n;i++)
{
System.out.print(i+" ");

}
n--;
System.out.println();
}
}
}

You might also like