Pattern output using Java program

Here is a set of Java programs that are written to generate pattern output (like alphabet pattern). These programs are useful for students who are learning Java (or BlueJ) programming.

Students of ICSE, CBSE, and state boards of India will find it useful to prepare their school projects as well as board projects.

Alphabet pattern using Java program

class AlphabetsPattern
{


public static void main(String abc[])
{
for(int i=1;i<6;i++)
{
int alphabet=97; //ASCII value of A
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
alphabet++;
}


System.out.println();
}
}
}

Print a pattern using Java program – Program 2

import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)


{
Scanner sc = new Scanner(System.in);
System.out.println(“How many rows you want in this pattern?”);
int rows = sc.nextInt();
System.out.println(“Here is your pattern….!!!”);
for (int i = rows; i >= 1; j-=2)

{
for (int j = rows; j >= i; j-=2)
{
System.out.print(j+” “);
}
System.out.println();
}


sc.close();
}
}

Print a pattern using Java program – Program 3

public class Pattern {
public static void main(String[] args) {
int rows = 5, k = 0, count = 0, count1 = 0;
for(int i = 1; i <= rows; ++i)

{
for(int space = 1; space <= rows – i; ++space) {
System.out.print(” “);
++count;
}


while(k != 2 * i – 1) {
if (count <= rows – 1) {
System.out.print((i + k) + ” “);
++count;
}
else {
++count1;

System.out.print((i + k – 2 * count1) + ” “);
}


++k;
}
count1 = count = k = 0;
System.out.println();
}
}
}

Pattern output using Java program
Scroll to top
error: physicsTeacher.in