Java Program to Print Alphabets from A to Z

Learn how to print alphabets from A to Z in Java using a for loop and ASCII values. By converting integer values into characters, we can easily print all uppercase English letters.

Code Explanation (Step-by-Step)

  • Declare an integer variable x and assign the ASCII value of A (65).
  • Use a for loop to iterate from 0 to 25.
  • Add the loop counter value to x.
  • Convert the result into a character using type casting.
  • Print each alphabet on the console.
				
					public class AlphabetPrint {

	public static void main(String[] args) {
		int x = 65;

		for (int i = 0; i < 26; i++) {
			System.out.print((char) (i + x) + " ");
		}
	}
}
				
			

Output :-
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Java 8 Program to Display Alphabets from A to Z

				
					import java.util.stream.IntStream;

public class AlphabetPrint {

	public static void main(String[] args) {

		IntStream.rangeClosed('A', 'Z')
				 .forEach(ch -> System.out.print((char) ch + " "));
	}
}
				
			

ASCII Values of Alphabets

ASCII (American Standard Code for Information Interchange) assigns a numeric value to each character. The ASCII values of uppercase alphabets range from 65 to 90, while the ASCII values of lowercase alphabets range from 97 to 122. In Java, these values can be converted into characters using type casting with the char data type.

FAQ
How do you print alphabets from A to Z in Java?
You can print alphabets from A to Z using a for loop and character type casting from ASCII values.
What is the ASCII value of A in Java?
The ASCII value of uppercase A is 65.
Why is character casting used in this program?
Character casting converts integer ASCII values into their corresponding alphabet characters.
Can I print lowercase alphabets in Java?
Yes. Use the ASCII value 97 for lowercase a and iterate up to 122 for z.