In this blog post you will find set 3 of character patterns. We recommend you to solve other types patterns as well –
Click on the pattern and you will get redirected to the code.
Pattern 1
A BC DEF GHIJ KLMNO PQRSTU
Code for pattern 1
Java
C++
Python
JavaScript
Java
public class MainClass {
public static void main(String[] args) {
int count=0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if(j-i<=0)
System.out.print((char)(count++ +65));
else
System.out.print(" ");
}
System.out.println();
}
}
}
C++
#include
int main() {
int count = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (j - i <= 0) {
std::cout << (char)(count++ + 65);
} else {
std::cout << " ";
}
}
std::cout << std::endl;
}
return 0;
};
Python
class MainClass :
@staticmethod
def main( args) :
count = 0
i = 0
while (i < 6) :
j = 0
while (j < 6) :
if (j - i <= 0) :
print(chr((count + 65)), end ="")
count += 1
else :
print(" ", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
MainClass.main([])
JavaScript
class MainClass {
static main(args) {
var count = 0;
for (i; i < 6; i++) {
for (j; j < 6; j++) {
if (j - i <= 0) {
console.log(String.fromCharCode((count++ + 65)));
} else {
console.log(" ");
}
}
console.log();
}
}
}
MainClass.main([]);
Pattern 2
A BA CBA DCBA EDCBA FEDCBA
Code for pattern 2
Java
C++
Python
JavaScript
Java
public class MainClass {
public static void main(String[] args) {
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if(j-i<=0)
System.out.print((char)(+i-j+65));
else
System.out.print(" ");
}
System.out.println();
}
}
}
C++
#include
int main() {
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (j - i <= 0) {
std::cout << (char)(+i - j + 65);
} else {
std::cout << " ";
}
}
std::cout << std::endl;
}
return 0;
};
Python
class MainClass :
@staticmethod
def main( args) :
i = 0
while (i < 6) :
j = 0
while (j < 6) :
if (j - i <= 0) :
print(chr((+i - j + 65)), end ="")
else :
print(" ", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
MainClass.main([])
JavaScript
class MainClass {
static main(args) {
for (i; i < 6; i++) {
for (j; j < 6; j++) {
if (j - i <= 0) {
console.log(String.fromCharCode((+i - j + 65)));
} else {
console.log(" ");
}
}
console.log();
}
}
}
MainClass.main([]);
Pattern 3
A BG CHM DINS EJOTY FKPUZ_
Code for pattern 3
Java
C++
Python
JavaScript
Java
public class MainClass {
public static void main(String[] args) {
int num=0;
for (int i = 0; i < 6; i++) {
int num2=num;
int def=5;
for (int j = 0; j < 6; j++) {
if(j-i<=0) {
System.out.print((char)(num2+65));
num2= num2+def;
}
}
System.out.println();
num++;
}
}
}
C++
#include
int main() {
int num = 0;
for (int i = 0; i < 6; i++) {
int num2 = num;
int def = 5;
for (int j = 0; j < 6; j++) {
if (j - i <= 0) {
std::cout << (char)(num2 + 65);
num2 = num2 + def;
}
}
std::cout << std::endl;
num++;
}
return 0;
};
Python
class MainClass :
@staticmethod
def main( args) :
num = 0
i = 0
while (i < 6) :
num2 = num
k = 5
j = 0
while (j < 6) :
if (j - i <= 0) :
print(chr((num2 + 65)), end ="")
num2 = num2 + k
j += 1
print()
num += 1
i += 1
if __name__=="__main__":
MainClass.main([])
JavaScript
class MainClass {
static main(args) {
var num = 0;
for (i; i < 6; i++) {
var num2 = num;
var def = 5;
for (j; j < 6; j++) {
if (j - i <= 0) {
console.log(String.fromCharCode((num2 + 65)));
num2 = num2 + def;
}
}
console.log();
num++;
}
}
}
MainClass.main([]);
Pattern 4
A AB ABC ABCD ABCDE ABCD ABC AB A
Code for pattern 4
Java
C++
Python
JavaScript
Java
public class MainClass {
public static void main(String[] args) {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 5; j++) {
if(j-i<=0 && j+i<=8 )
System.out.print((char)(j+65));
else
System.out.print("");
}
System.out.println();
}
}
}
C++
#include
int main() {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 5; j++) {
if (j - i <= 0 && j + i <= 8) {
std::cout << (char)(j + 65);
} else {
std::cout << "";
}
}
std::cout << std::endl;
}
return 0;
};
Python
class MainClass :
@staticmethod
def main( args) :
i = 0
while (i < 9) :
j = 0
while (j < 5) :
if (j - i <= 0 and j + i <= 8) :
print(chr((j + 65)), end ="")
else :
print("", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
MainClass.main([])
JavaScript
class MainClass {
static main(args) {
for (i; i < 9; i++) {
for (j; j < 5; j++) {
if (j - i <= 0 && j + i <= 8) {
console.log(String.fromCharCode((j + 65)));
} else {
console.log("");
}
}
console.log();
}
}
}
MainClass.main([]);
Pattern 5
ABCDEF ABCDE ABCD ABC AB A A AB ABC ABCD ABCDE ABCDEF
Code for pattern 5
Java
C++
Python
JavaScript
Java
public class MainClass {
public static void main(String[] args) {
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 6; j++) {
if(j-i<=-6 || j+i<=5 )
System.out.print((char)(j+65));
else
System.out.print("");
}
System.out.println();
}
}
}
C++
#include
int main() {
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 6; j++) {
if (j - i <= -6 || j + i <= 5) {
std::cout << (char)(j + 65);
} else {
std::cout << "";
}
}
std::cout << std::endl;
}
return 0;
};
Python
class MainClass :
@staticmethod
def main( args) :
i = 0
while (i < 12) :
j = 0
while (j < 6) :
if (j - i <= -6 or j + i <= 5) :
print(chr((j + 65)), end ="")
else :
print("", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
MainClass.main([])
JavaScript
class MainClass {
static main(args) {
for (i; i < 12; i++) {
for (j; j < 6; j++) {
if (j - i <= -6 || j + i <= 5) {
console.log(String.fromCharCode((j + 65)));
} else {
console.log("");
}
}
console.log();
}
}
}
MainClass.main([]);