How to Print ASCII values in Java | EasyCoding45

Write a Java Program that prints ASCII values from A to Z.


To print ASCII values from 'A' to 'Z' in Java, you can use a loop to iterate through the characters and print their ASCII values. In this example, the loop runs from 'A' to 'Z', and for each character, it prints its ASCII value. The (int) cast is used to convert the character to its ASCII value.


Program : (How to Print ASCII values in Java)

public class AsciiValuesAZExample {
    public static void main(String[] args) {
        // ASCII values for 'A' to 'Z'
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            int asciiValue = (int) ch;
            System.out.println("ASCII value of " + ch + " is " + asciiValue);
        }
    }
}

Output :

https://easycoding45.blogspot.com/2023/11/how-to-print-ascii-values-in-java.html




Comments