Learn Java Coding

Everything You Have To Know About Java

Loop/Print from A to Z

Printing from A to Z by adding numbers in a loop

It is good to know that, besides counting numbers, it is also possible to count with letters in java. We will do this with the type char. The type char contains 65,535 characters. You could check this yourself

(but it will cost much computing power, so it could be that your computer can’t handle that. Therefore you could change the 65535 to a smaller number like 100)

by making a for-loop which runs through all the characters and print them one-for-one:

for (char alphabet = 0; alphabet <= 65535; alphabet++) {
	out.print(alphabet);
}

When you want to print the alphabet, for example, you could also say: oke java, go from a to z and print them, like this:

for (char alphabet = 'a'; alphabet <= 'z'; alphabet++) {
	out.print(alphabet);
}

It is also fun for some people to make different shapes when printing, for example, the alphabet. See the next page: Pyramids.

Next Post

Previous Post

© 2024 Learn Java Coding