C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Java programs

Java program to print star pattern using class

Submitted by BalRam Dixit, on May 18, 2017
STAR pattern printing program in Java - This program will print the star pattern till N lines, N will be taken as input from the user.

In this program, we are going to write java code to print the pattern; this program will contain a class, program will take an input from the user and print the pattern according to the input value.

Consider the program

import java.util.Scanner;

public class Pattern1{
	private int num;
	public void setNum(int num){
	public int getNum(){
		return this.num;
	public void printAnswer(){
		for(int i=1;i<=getNum();i++){
			for(int j=1;j<=i;j++){
				System.out.print(" *");
	public void inputNum(){
        Scanner sc  =   new Scanner(System.in);
        System.out.print("Enter Number  : ");
        int num =   sc.nextInt();
	public static void main(String[] ar){
		Pattern1 ob = new Pattern1();


Enter Number  : 5
 * *
 * * *
 * * * *
 * * * * *

You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions