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
48 changes: 48 additions & 0 deletions patterns/DiamondStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.company.patterns;

import java.util.Scanner;

public class DiamondStar {
public static void main(String[] args) {

// *
// ***
// *****
// *******
// *********
// *******
// *****
// ***
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

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

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

}
}
35 changes: 35 additions & 0 deletions patterns/HalfDiamondStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.company.patterns;

import java.util.Scanner;

public class HalfDiamondStar {
public static void main(String[] args) {

// *
// **
// ***
// ****
// *****
// ****
// ***
// **
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

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

for(int i = 1; i<=rows; i++){
for(int j = i; j<rows; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
27 changes: 27 additions & 0 deletions patterns/InvertedMirroredRightTriangleStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.company.patterns;

import java.util.Scanner;

public class InvertedMirroredRightTriangleStar {
public static void main(String[] args) {

// *****
// ****
// ***
// **
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; ++i){
for(int j = 1; j<=i; j++){
System.out.print(" ");
}
for(int j = i; j<=rows; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
30 changes: 30 additions & 0 deletions patterns/InvertedPyramidStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.company.patterns;

import java.util.Scanner;

public class InvertedPyramidStar {
public static void main(String[] args) {

// *********
// *******
// *****
// ***
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; i++){
for(int j = 1; j<=i; j++){
System.out.print(" ");
}
for(int j = i; j<rows; j++){
System.out.print("*");
}
for(int j = i; j<=rows; j++){
System.out.print("*");
}
System.out.println();
}
}
}
29 changes: 29 additions & 0 deletions patterns/InvertedRightTriangleStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.company.patterns;

import java.util.Scanner;

public class InvertedRightTriangleStar {
public static void main(String[] args) {

// *****
// ****
// ***
// **
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; ++i){
for(int j = 1; j<=rows; j++){
if(i+j <= rows + 1){
System.out.print("*");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
42 changes: 42 additions & 0 deletions patterns/MirroredHalfDiamondStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.company.patterns;

import java.util.Scanner;

public class MirroredHalfDiamondStar {
public static void main(String[] args) {

// *
// **
// ***
// ****
// *****
// ****
// ***
// **
// *

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

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

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

}
}
29 changes: 29 additions & 0 deletions patterns/MirroredRightTriangleStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.company.patterns;

import java.util.Scanner;

public class MirroredRightTriangleStar {
public static void main(String[] args) {

// *
// **
// ***
// ****
// *****

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; ++i){
for(int j = 1; j<=rows; j++){
if(i+j >= rows + 1){
System.out.print("*");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
30 changes: 30 additions & 0 deletions patterns/PyramidStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.company.patterns;

import java.util.Scanner;

public class PyramidStar {
public static void main(String[] args) {

// *
// ***
// *****
// *******
// *********

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; i++){
for(int j = i; j<=rows; j++){
System.out.print(" ");
}
for(int j = 1; j<i; j++){
System.out.print("*");
}
for(int j = 1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
24 changes: 24 additions & 0 deletions patterns/RightAngledTriangleStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.company.patterns;

import java.util.Scanner;

public class RightAngledTriangleStar {
public static void main(String[] args) {

// *
// **
// ***
// ****
// *****

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

for(int i = 1; i<=rows; ++i){
for(int j = 1; j<=i; ++j){
System.out.print("*");
}
System.out.println();
}
}
}
25 changes: 25 additions & 0 deletions patterns/SquareStar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.company.patterns;

import java.util.Scanner;

public class SquareStar {

public static void main(String[] args) {

// *****
// *****
// *****
// *****
// *****

Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();

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