CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Java Examples

Java

    Introduction

    • Java - Overview
    • Installation & Setup
    • Program Structure
    • Keywords & Identifiers
    • Basic Data Types
    • Access Modifiers
    • Operators
    • Loops
    • Decision Statements

    Java Examples

    • Print an Integer
    • Add Two Integers
    • Multiply Two Floating Point Numbers
    • Find Ascii Value
    • Compute Quotient & Remainder
    • Swap Two Numbers using Temporary Variable
    • Swap Two Numbers without using Temporary Variable

Java Program to Find ASCII Value of a character

In this java program, you'll learn how to find ASCII value of a character and display the result in the console.

How to Find ASCII Value of a character in Java?

Sourcecode

/*
    Author : CodersEditor.com
    Program : How to Find ASCII Value of a character in Java?
*/
public class Main {

    public static void main(String[] args) {

        char characterInput = 'A';
        int ascii = characterInput;

        System.out.println("The Ascii value of " + characterInput + " is: " + ascii);
    }
}

Output

The Ascii value of A is: 65

Explanation

  • In this java program, the character "A" is stored in a variable of type char.
  • we just assign the character variable to integer which would be converted by Java internally to the integer (ascii value).
  • The result is displayed in the console using System.out.print function.
note
  1. Single quotes (') is used to declare characters in Java. Double quotes(") is used to declare strings in java.
  2. Alternatively, You can find the ascii value by casting the character to integer using (int)
← Multiply Two Floating Point NumbersCompute Quotient & Remainder →
  • How to Find ASCII Value of a character in Java?
    • Sourcecode
    • Output
    • Explanation
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com