In this program, we are going to see how we can print alphabets in Java. The program is pretty simple and straight forward. Here ASCII value of the characters comes into the picture, we use the ASCII value of starting and end character to run the loop.
See also: Find ASCII value of a character
Logic
ASCII value of small letter “a” is 97 and for “z” it is 122, so we run the loop from 97 to 122 and then inside the loop we have to print the current character.
Program
import java.util.Scanner; public class PrintAlphbet { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Alphabets from a - z are : "); for(char c = 'a'; c <= 'z'; c++) { System.out.print(c + " "); } } }
Output
Alphabets from a - z are:
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