Write a Java Program to Display Alphabets A to Z using Loop

As a Java programmer, displaying alphabets A to Z using a loop is a basic task that can be accomplished using a for or while loop.

In this tutorial, we will demonstrate how to display the English alphabets in ascending order from A to Z using a for loop.


Java Program to Display Alphabets A to Z using Loop

public class AlphabetLoop {
  public static void main(String[] args) {
    char ch;
    for(ch = 'A'; ch <= 'Z'; ch++){
      System.out.print(ch + " ");
    }
  }
}

Explanation

  1. The class AlphabetLoop is declared, and the main method is defined.
  2. The char variable ch is declared.
  3. A for loop is used to iterate through the English alphabets from ‘A’ to ‘Z’.
  4. Within the for loop, the System.out.print method is used to display each alphabet, separated by a space.
  5. The output of the program will be the alphabets A to Z, separated by a space.

Conclusion

In conclusion, displaying the English alphabets from A to Z using a for loop in Java is a simple task that can be accomplished with a few lines of code.

This program is useful when working with applications that require alphabetical inputs or when testing alphabetical data inputs.

By understanding the basics of Java loops, we can develop more complex programs that require iterative processing.