SlideShare a Scribd company logo
Programs for printing pyramid patterns in Java
This article is aimed at giving a Java implementation for pattern printing.
Simple pyramid pattern
filter_none
edit
play_arrow
brightness_4
import java.io.*;
// Java code to demonstrate star patterns
public class My_Class
{
// Function to demonstrate printing pattern
public static void printStars(int n)
{
int i, j;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printStars(n);
}
}
Output:
*
* *
* * *
* * * *
* * * * *
After 180 degree rotation
filter_none
edit
play_arrow
brightness_4
import java.io.*;
// Java code to demonstrate star pattern
public class My_Class
{
// Function to demonstrate printing pattern
public static void printStars(int n)
{
int i, j;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// inner loop to handle number spaces
// values changing acc. to requirement
for(j=2*(n-i); j>=0; j--)
{
// printing spaces
System.out.print(" ");
}
// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printStars(n);
}
}
Output:
*
* *
* * *
* * * *
* * * * *
Printing Triangle
filter_none
edit
play_arrow
brightness_4
import java.io.*;
// Java code to demonstrate star pattern Print Star pattern in Java
public class My_Class
{
// Function to demonstrate printing pattern
public static void printTriagle(int n)
{
// outer loop to handle number of rows
// n in this case
for (int i=0; i<n; i++)
{
// inner loop to handle number spaces
// values changing acc. to requirement
for (int j=n-i; j>1; j--)
{
// printing spaces
System.out.print(" ");
}
// inner loop to handle number of columns
// values changing acc. to outer loop
for (int j=0; j<=i; j++ )
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printTriagle(n);
}
}
Output:
*
* *
* * *
* * * *
* * * * *
Number Pattern
filter_none
edit
play_arrow
brightness_4
import java.io.*;
// Java code to demonstrate number pattern
public class My_Class
{
// Function to demonstrate printing pattern
public static void printNums(int n)
{
int i, j,num;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// initialising starting number
num=1;
// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing num with a space
System.out.print(num+ " ");
//incrementing value of num
num++;
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printNums(n);
}
}
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Numbers without re assigning
filter_none
edit
play_arrow
brightness_4
import java.io.*;
// Java code to demonstrate star pattern
public class My_Class
{
// Function to demonstrate printing pattern
public static void printNums(int n)
{
// initialising starting number
int i, j, num=1;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// without re assigning num
// num = 1;
for(j=0; j<=i; j++)
{
// printing num with a space
System.out.print(num+ " ");
// incrementing num at each column
num = num + 1;
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printNums(n);
}
}
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

More Related Content

What's hot

Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
Hiraniahmad
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
NUST Stuff
 
Function
FunctionFunction
Function
yash patel
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
manhduc1811
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design PatternAsif Tayef
 
Replace OutputIterator and Extend Range
Replace OutputIterator and Extend RangeReplace OutputIterator and Extend Range
Replace OutputIterator and Extend Range
Akira Takahashi
 
C++20 features
C++20 features C++20 features
C++20 features
LogeekNightUkraine
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
Andrey Karpov
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.
Mohamed Fawzy
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
Python Homework Help
 
Import java
Import javaImport java
Import java
heni2121
 
C++ references
C++ referencesC++ references
C++ references
corehard_by
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
Ankit Gupta
 
Catch and throw blocks
Catch and throw blocksCatch and throw blocks
Catch and throw blocks
ashrafkhan12345
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
ssuserd6b1fd
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
Javascript OOP
Javascript OOPJavascript OOP
Javascript OOP
Miao Siyu
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
SURBHI SAROHA
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
SURBHI SAROHA
 

What's hot (20)

Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
Function
FunctionFunction
Function
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
 
Replace OutputIterator and Extend Range
Replace OutputIterator and Extend RangeReplace OutputIterator and Extend Range
Replace OutputIterator and Extend Range
 
C++20 features
C++20 features C++20 features
C++20 features
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 
Import java
Import javaImport java
Import java
 
C++ references
C++ referencesC++ references
C++ references
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Catch and throw blocks
Catch and throw blocksCatch and throw blocks
Catch and throw blocks
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
Javascript OOP
Javascript OOPJavascript OOP
Javascript OOP
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 

Similar to Print Star pattern in java and print triangle of stars in java

Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
gersonjack
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Estructura secuencial -garcia
Estructura secuencial -garciaEstructura secuencial -garcia
Estructura secuencial -garcia
Daneziita Laulate Flores
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
Hiraniahmad
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
walia Shaan
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
Ankit Gupta
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
dorisc7
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
Karthik Rohan
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
angelsfashion1
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
jonbodner
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
aptcomputerzone
 

Similar to Print Star pattern in java and print triangle of stars in java (20)

Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Estructura secuencial -garcia
Estructura secuencial -garciaEstructura secuencial -garcia
Estructura secuencial -garcia
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 

Recently uploaded

The Role of Non-Banking Financial Companies (NBFCs)
The Role of Non-Banking Financial Companies (NBFCs)The Role of Non-Banking Financial Companies (NBFCs)
The Role of Non-Banking Financial Companies (NBFCs)
nickysharmasucks
 
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
nexop1
 
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
beulahfernandes8
 
The European Unemployment Puzzle: implications from population aging
The European Unemployment Puzzle: implications from population agingThe European Unemployment Puzzle: implications from population aging
The European Unemployment Puzzle: implications from population aging
GRAPE
 
Transkredit Finance Company Products Presentation (1).pptx
Transkredit Finance Company Products Presentation (1).pptxTranskredit Finance Company Products Presentation (1).pptx
Transkredit Finance Company Products Presentation (1).pptx
jenomjaneh
 
Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024
Commercial Bank of Ceylon PLC
 
Analyzing the instability of equilibrium in thr harrod domar model
Analyzing the instability of equilibrium in thr harrod domar modelAnalyzing the instability of equilibrium in thr harrod domar model
Analyzing the instability of equilibrium in thr harrod domar model
ManthanBhardwaj4
 
PF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptxPF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptx
GunjanSharma28848
 
Scope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theoriesScope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theories
nomankalyar153
 
what is the best method to sell pi coins in 2024
what is the best method to sell pi coins in 2024what is the best method to sell pi coins in 2024
what is the best method to sell pi coins in 2024
DOT TECH
 
how can I sell/buy bulk pi coins securely
how can I sell/buy bulk pi coins securelyhow can I sell/buy bulk pi coins securely
how can I sell/buy bulk pi coins securely
DOT TECH
 
how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.
DOT TECH
 
how can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYChow can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYC
DOT TECH
 
Instant Issue Debit Cards - School Designs
Instant Issue Debit Cards - School DesignsInstant Issue Debit Cards - School Designs
Instant Issue Debit Cards - School Designs
egoetzinger
 
Seminar: Gender Board Diversity through Ownership Networks
Seminar: Gender Board Diversity through Ownership NetworksSeminar: Gender Board Diversity through Ownership Networks
Seminar: Gender Board Diversity through Ownership Networks
GRAPE
 
how to swap pi coins to foreign currency withdrawable.
how to swap pi coins to foreign currency withdrawable.how to swap pi coins to foreign currency withdrawable.
how to swap pi coins to foreign currency withdrawable.
DOT TECH
 
BYD SWOT Analysis and In-Depth Insights 2024.pptx
BYD SWOT Analysis and In-Depth Insights 2024.pptxBYD SWOT Analysis and In-Depth Insights 2024.pptx
BYD SWOT Analysis and In-Depth Insights 2024.pptx
mikemetalprod
 
how to sell pi coins on Binance exchange
how to sell pi coins on Binance exchangehow to sell pi coins on Binance exchange
how to sell pi coins on Binance exchange
DOT TECH
 
Turin Startup Ecosystem 2024 - Ricerca sulle Startup e il Sistema dell'Innov...
Turin Startup Ecosystem 2024  - Ricerca sulle Startup e il Sistema dell'Innov...Turin Startup Ecosystem 2024  - Ricerca sulle Startup e il Sistema dell'Innov...
Turin Startup Ecosystem 2024 - Ricerca sulle Startup e il Sistema dell'Innov...
Quotidiano Piemontese
 
Which Crypto to Buy Today for Short-Term in May-June 2024.pdf
Which Crypto to Buy Today for Short-Term in May-June 2024.pdfWhich Crypto to Buy Today for Short-Term in May-June 2024.pdf
Which Crypto to Buy Today for Short-Term in May-June 2024.pdf
Kezex (KZX)
 

Recently uploaded (20)

The Role of Non-Banking Financial Companies (NBFCs)
The Role of Non-Banking Financial Companies (NBFCs)The Role of Non-Banking Financial Companies (NBFCs)
The Role of Non-Banking Financial Companies (NBFCs)
 
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
一比一原版(UoB毕业证)伯明翰大学毕业证如何办理
 
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
The Evolution of Non-Banking Financial Companies (NBFCs) in India: Challenges...
 
The European Unemployment Puzzle: implications from population aging
The European Unemployment Puzzle: implications from population agingThe European Unemployment Puzzle: implications from population aging
The European Unemployment Puzzle: implications from population aging
 
Transkredit Finance Company Products Presentation (1).pptx
Transkredit Finance Company Products Presentation (1).pptxTranskredit Finance Company Products Presentation (1).pptx
Transkredit Finance Company Products Presentation (1).pptx
 
Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024
 
Analyzing the instability of equilibrium in thr harrod domar model
Analyzing the instability of equilibrium in thr harrod domar modelAnalyzing the instability of equilibrium in thr harrod domar model
Analyzing the instability of equilibrium in thr harrod domar model
 
PF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptxPF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptx
 
Scope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theoriesScope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theories
 
what is the best method to sell pi coins in 2024
what is the best method to sell pi coins in 2024what is the best method to sell pi coins in 2024
what is the best method to sell pi coins in 2024
 
how can I sell/buy bulk pi coins securely
how can I sell/buy bulk pi coins securelyhow can I sell/buy bulk pi coins securely
how can I sell/buy bulk pi coins securely
 
how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.
 
how can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYChow can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYC
 
Instant Issue Debit Cards - School Designs
Instant Issue Debit Cards - School DesignsInstant Issue Debit Cards - School Designs
Instant Issue Debit Cards - School Designs
 
Seminar: Gender Board Diversity through Ownership Networks
Seminar: Gender Board Diversity through Ownership NetworksSeminar: Gender Board Diversity through Ownership Networks
Seminar: Gender Board Diversity through Ownership Networks
 
how to swap pi coins to foreign currency withdrawable.
how to swap pi coins to foreign currency withdrawable.how to swap pi coins to foreign currency withdrawable.
how to swap pi coins to foreign currency withdrawable.
 
BYD SWOT Analysis and In-Depth Insights 2024.pptx
BYD SWOT Analysis and In-Depth Insights 2024.pptxBYD SWOT Analysis and In-Depth Insights 2024.pptx
BYD SWOT Analysis and In-Depth Insights 2024.pptx
 
how to sell pi coins on Binance exchange
how to sell pi coins on Binance exchangehow to sell pi coins on Binance exchange
how to sell pi coins on Binance exchange
 
Turin Startup Ecosystem 2024 - Ricerca sulle Startup e il Sistema dell'Innov...
Turin Startup Ecosystem 2024  - Ricerca sulle Startup e il Sistema dell'Innov...Turin Startup Ecosystem 2024  - Ricerca sulle Startup e il Sistema dell'Innov...
Turin Startup Ecosystem 2024 - Ricerca sulle Startup e il Sistema dell'Innov...
 
Which Crypto to Buy Today for Short-Term in May-June 2024.pdf
Which Crypto to Buy Today for Short-Term in May-June 2024.pdfWhich Crypto to Buy Today for Short-Term in May-June 2024.pdf
Which Crypto to Buy Today for Short-Term in May-June 2024.pdf
 

Print Star pattern in java and print triangle of stars in java

  • 1. Programs for printing pyramid patterns in Java This article is aimed at giving a Java implementation for pattern printing. Simple pyramid pattern filter_none edit play_arrow brightness_4 import java.io.*; // Java code to demonstrate star patterns public class My_Class { // Function to demonstrate printing pattern public static void printStars(int n) { int i, j; // outer loop to handle number of rows // n in this case for(i=0; i<n; i++) { // inner loop to handle number of columns // values changing acc. to outer loop for(j=0; j<=i; j++) {
  • 2. // printing stars System.out.print("* "); } // ending line after each row System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; printStars(n); } } Output: * * * * * * * * * * * * * * * After 180 degree rotation
  • 3. filter_none edit play_arrow brightness_4 import java.io.*; // Java code to demonstrate star pattern public class My_Class { // Function to demonstrate printing pattern public static void printStars(int n) { int i, j; // outer loop to handle number of rows // n in this case for(i=0; i<n; i++) { // inner loop to handle number spaces // values changing acc. to requirement for(j=2*(n-i); j>=0; j--) { // printing spaces System.out.print(" "); }
  • 4. // inner loop to handle number of columns // values changing acc. to outer loop for(j=0; j<=i; j++) { // printing stars System.out.print("* "); } // ending line after each row System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; printStars(n); } } Output: * * * * * * * * * * * * * * * Printing Triangle
  • 5. filter_none edit play_arrow brightness_4 import java.io.*; // Java code to demonstrate star pattern Print Star pattern in Java public class My_Class { // Function to demonstrate printing pattern public static void printTriagle(int n) { // outer loop to handle number of rows // n in this case for (int i=0; i<n; i++) { // inner loop to handle number spaces // values changing acc. to requirement for (int j=n-i; j>1; j--) { // printing spaces System.out.print(" "); } // inner loop to handle number of columns // values changing acc. to outer loop
  • 6. for (int j=0; j<=i; j++ ) { // printing stars System.out.print("* "); } // ending line after each row System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; printTriagle(n); } } Output: * * * * * * * * * * * * * * * Number Pattern filter_none
  • 7. edit play_arrow brightness_4 import java.io.*; // Java code to demonstrate number pattern public class My_Class { // Function to demonstrate printing pattern public static void printNums(int n) { int i, j,num; // outer loop to handle number of rows // n in this case for(i=0; i<n; i++) { // initialising starting number num=1; // inner loop to handle number of columns // values changing acc. to outer loop for(j=0; j<=i; j++) { // printing num with a space System.out.print(num+ " "); //incrementing value of num
  • 8. num++; } // ending line after each row System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; printNums(n); } } Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Numbers without re assigning filter_none edit play_arrow
  • 9. brightness_4 import java.io.*; // Java code to demonstrate star pattern public class My_Class { // Function to demonstrate printing pattern public static void printNums(int n) { // initialising starting number int i, j, num=1; // outer loop to handle number of rows // n in this case for(i=0; i<n; i++) { // without re assigning num // num = 1; for(j=0; j<=i; j++) { // printing num with a space System.out.print(num+ " "); // incrementing num at each column num = num + 1; } // ending line after each row
  • 10. System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; printNums(n); } } Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15