-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintJava.java
88 lines (81 loc) · 2.75 KB
/
printJava.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Scanner;
class PrintJava{
void printJava(){
System.out.println("\n printing simply by strings \n===========================================\n");
System.out.println(" J A V V A ");
System.out.println(" J A A V V A A ");
System.out.println(" J A A V V A A ");
System.out.println(" J J AAAAAAAAA V V AAAAAAAAA ");
System.out.println(" JJJJJJJ A A V A A ");
System.out.println("\n");
}
void printChar(String string, int frequency){
while (frequency > 0) {
System.out.print(string);
frequency--;
}
}
void printLetterJ(int rowIndex){
if (rowIndex < 3){
this.printChar(" ",8);
this.printChar("J",1);
}
else if(rowIndex == 3){
this.printChar("j",1);
this.printChar(" ",7);
this.printChar("J",1);
}
else{
this.printChar(" ",1);
this.printChar("J",7);
this.printChar(" ",1);
}
}
void printLetterA(int rowIndex){
int base = 5;
int leftLocation = base - rowIndex;
int rightLocation = base + rowIndex;
if (rowIndex == 3) {
this.printChar(" ",1);
this.printChar("A",7);
this.printChar(" ",1);
return;
}
for (int index = 1; index <= 9; index++) {
if (index == leftLocation || index == rightLocation )
System.out.print("A");
else
System.out.print(" ");
}
}
void printLetterV(int rowIndex){
int base = 9;
int leftLocation = rowIndex + 1;
int rightLocation = base - rowIndex;
for (int index = 1; index <= 9; index++) {
if (index == leftLocation || index == rightLocation )
System.out.print("V");
else
System.out.print(" ");
}
}
void printJavaByLoop(){
System.out.println("\n printing JAVA with help of loops \n===========================================\n");
for (int i = 0; i < 5; i++) {
System.out.print(" ");
this.printLetterJ(i);
System.out.print(" ");
this.printLetterA(i);
System.out.print(" ");
this.printLetterV(i);
System.out.print(" ");
this.printLetterA(i);
System.out.println(" ");
}
}
public static void main(String[] args) {
PrintJava java = new PrintJava();
java.printJava();
java.printJavaByLoop();
}
}