Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Triangle_PrintingStar/triamgle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.*; // package to use Scanner class
class pattern {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows to be printed");
int rows = sc.nextInt();

// loop to iterate for the given number of rows
for (int i = 1; i <= rows; i++) {

// loop to print the number of spaces before the star
for (int j = rows; j >= i; j--) {
System.out.print(" ");
}

// loop to print the number of stars in each row
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}

// for new line after printing each row
System.out.println();
}
}
}
22 changes: 22 additions & 0 deletions Triangle_PrintingStar/triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Scanner;

public class triangle {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
System.out.println("Enetr the no");
int n=sc.nextInt();

for(int i=1;i<=n;i++) {
for(int j=1;j<=i-1;j++) {
System.out.print(" ");
}
for(int j=1;j<=n-i+1;j++) {
System.out.print("*");
}
System.out.println(" ");

}
}
}
28 changes: 28 additions & 0 deletions Triangle_PrintingStar/triangle1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Java Program to print the given pattern
import java.util.*; // package to use Scanner class
class triangle1 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows to be printed");
int rows = sc.nextInt();
int number=1;
// loop to iterate for the given number of rows
for (int i = 1; i <= rows; i++) {

// loop to print the number of spaces before the star
for (int j = rows; j >= i; j--) {
System.out.print(" ");
}

// loop to print the number of stars in each row
for (int j = 1; j <= i; j++) {
System.out.print(number+" ");
number++;
}

// for new line after printing each row
System.out.println();
}
}
}
26 changes: 26 additions & 0 deletions Triangle_PrintingStar/triangle2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class triangle2 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
System.out.println("Enetr the no");
int n=sc.nextInt();

for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println("");
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n-i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
30 changes: 30 additions & 0 deletions Triangle_PrintingStar/triangle3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.Scanner;

public class triangle3 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
System.out.println("Enetr the no");
int n=sc.nextInt();

System.out.println("*");
for(int i=2;i<=n-1;i++)
{
System.out.print("* ");

for (int j=1;j<=i-2;j++)
{
System.out.print(" ");
}

System.out.print("* ");

System.out.println();
}
for(int i=1;i<=n;i++) {
System.out.print("* ");
}
}

}
12 changes: 12 additions & 0 deletions Triangle_PrintingStar/triangle4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.util.Scanner;

public class triangle4 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
System.out.println("Enetr the no");
int n=sc.nextInt();
}

}