-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from 6736-shafi/master
updated pattern12
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package AlphabetStarPattern; | ||
|
||
public class AlphabetStarPattern { | ||
public static void main(String[] args) { | ||
int i, j, n = 8; | ||
// Outer for loop for number of lines | ||
for (i = 0; i <= n; i++) { | ||
// Inner for loop for logic execution | ||
for (j = 0; j <= n / 2; j++) { | ||
// prints two vertical lines | ||
if ((j == 0 || j == n / 2) && i != 0 || | ||
// print first line of alphabet | ||
i == 0 && j != n / 2 || | ||
// prints middle line | ||
i == n / 2) | ||
System.out.print("*"); | ||
else | ||
System.out.print(" "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package SandglassStarPattern; | ||
|
||
import java.util.Scanner; | ||
|
||
public class SandglassStarPattern { | ||
public static void main(String[] args) { | ||
int i, j, k, n; | ||
Scanner sc = new Scanner(System.in); | ||
System.out.print("Enter the number of rows you want to print: "); | ||
n = sc.nextInt(); | ||
for (i = 0; i <= n - 1; i++) { | ||
for (j = 0; j < i; j++) { | ||
System.out.print(" "); | ||
} | ||
for (k = i; k <= n - 1; k++) { | ||
System.out.print("*" + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
for (i = n - 1; i >= 0; i--) { | ||
for (j = 0; j < i; j++) { | ||
System.out.print(" "); | ||
} | ||
for (k = i; k <= n - 1; k++) { | ||
System.out.print("*" + " "); | ||
} | ||
System.out.println(""); | ||
} | ||
sc.close(); | ||
} | ||
} |