Skip to content
Open
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
55 changes: 55 additions & 0 deletions Pattern_Printing/Letter_R.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Pattern_Printing;

/*

Expected output =

##@@@
## @@@
## @@@
## @@@
##@@@
## @@
## @@
## @@
## @@


*/

public class Letter_R {

public static void main(String[] args) {
//prints at the start of each line
final String HASH = "##";
//for upper half of the R
final String THREE_ATS = "@@@";
//for the lower half of the r
final String TWO_ATS = "@@";


var tabs = " ";
var spaces = new StringBuilder(" ");

//Loop through upper half of the R
for (int i = 1; i < 6; i++) {
System.out.print(HASH);
//determines if any indentation is necessary
if (i % 2 == 0) {
System.out.print(tabs);
} else if (i == 3) {
System.out.print(tabs+tabs);
}
//prints the ascii for the R
System.out.print(THREE_ATS + "\n");
}

//loop through lower half of the R
for (int i = 0; i < 4; i++) {
System.out.print(HASH);
System.out.print(spaces + TWO_ATS + "\n");
//increases the space with each iteration of loop
spaces.append(" ");
}
}
}