Pattern Program in java Language with Answers. In this tutorial we have discussed pattern program questions with solution.We have shared program based on star pattern, number pattern, pyramid pattern and alphabet pattern. We have discussed both basics and advanced level program in this tutorial
In java Language patterns programs are the best way to learn and practice loops. If anybody wants to improve their logical part then they must practice these programs. Following are the example of Star (*) pattern program in java Language.
*
**
***
****
*****
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
*****
****
***
**
*
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=i; j<=5; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Following are the example of numeric pattern programs
1
22
333
4444
55555
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
System.out.print(i);
}
System.out.println();
}
}
}
1
12
123
1234
12345
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
1
23
345
4567
56789
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=i; j<=(i*2)-1; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
1
21
321
4321
54321
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=1; i<=5; i++)
{
for(j=i;j>=1;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
55555
4444
333
22
1
package patternprogramjava;
public class PatternProgramJava {
public static void main(String[] args) {
int i,j;
for(i=5; i>=1; i--)
{
for(j=i;j>=1;j--)
{
System.out.print(i);
}
System.out.println();
}
}
}