Write a Java Program to display Alphabet from a to z using for loop, while loop, and do while loop. In this example, all the loops iterate from alphabets a to z and display them as an output.
public class Alphabetsatoz1 { public static void main(String[] args) { char lwch; for(lwch = 'a'; lwch <= 'z'; lwch++) { System.out.print(lwch + " "); } System.out.println(); char lwch1 = 'a'; while (lwch1 <= 'z') { System.out.print(lwch1 + " "); lwch1++; } System.out.println(); char lwch2 = 'a'; do { System.out.print(lwch2 + " "); } while (++lwch2 <= 'z'); } }
This program to display a to z iterates the ASCII codes from 97 to 122, representing the alphabets a to z, and prints them.
public class Example2 { public static void main(String[] args) { for(int i = 97; i <= 122; i++) { System.out.printf("%c ", i); } } }
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
This display Alphabets from a to z program allows users to enter the starting lowercase char and prints the remaining ones up to z.
import java.util.Scanner; public class Example3 { private static Scanner sc; public static void main(String[] args) { char ch, strlwChar; sc= new Scanner(System.in); System.out.print("Please Enter any Char = "); strlwChar = sc.next().charAt(0); for(ch = strlwChar; ch <= 'z'; ch++) { System.out.print(ch + " "); } } }
Please Enter any Char = h
h i j k l m n o p q r s t u v w x y z