Write a program to input a string and print each character of the string along with ASCII codes of each in two columns.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO PRINT EACH CHARACTER OF THE STRING ALONG WITH ITS ASCII CODES:

import java.util.*;

class ASCIIchar

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

        System.out.println("Enter a string");

        String s = ob.nextLine();

        for(int z = 0; z<s.length();z++)

        {

            char ch = s.charAt(z);

            int l  = (int)(ch);

            System.out.println("Characters \t ASCII CODES");

            System.out.println(ch+ "\t\t\t" +l);

        }

    }

}

INPUT:

Enter  a string 

askris

OUTPUT:

Characters           ASCII CODES

a                             97

s                             115

k                            107

r                             114

i                              105

s                             115

The above program CODE is compiled and is without any error.

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!



Comments

Popular Posts