Java Program to print the ASCII value of a character

Description

Get a character from user and display the corresponding ASCII value
Input 1:
A
Output 1:
65
Input 2:
J
Output 2:
74

Solution

import java.util.*;
class Ascii
{
 
    public static void main(String args[])
    {
       char ch;
       int ascii;
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter The Character:");
       ch=sc.next().charAt(0);
       ascii=(int)ch;
       System.out.println("Equivalent Ascii Value:"+ascii);
    }

}

Explanation

Scanner class is a function available(predefined) in java library to get input from user via keyboard and stores the same in a variable.

Here it reads input character and stores it in a variable 

System.out.println is a function available(pre defined) in java library which is used to print the specified content in Monitor.
                                                                                                                                                                                                                   type cast  is a predefine funtion to convert the data type.
                                                                                                                                                                                                                                              Here it prints the value of the variable .
Ramesh P Natarajan

Author - Ramesh P Natarajan

Learner, Professor, Technology Trainer, Software Developer and Content Marketer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: admin@decodeschool.com





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution