Computer Science, asked by shaunxylo, 7 months ago

Write a program to accept a name. Then display the ASCII value of each character present
in that name.

Write Variable Description and Comments]​

Answers

Answered by anindyaadhikari13
7

Here is your code.

<hr/>

import java.util.*;

class x

{

static void main()

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the name: ");

String s = sc.nextLine();

int len=s.length();

for(int i=0;i<len;i++)

{

char ch=s.charAt(i);

int ascii=(int)ch;

System.out.println("ASCII value of "+ch+" is: "+ascii);

}

}

}

&lt;hr/&gt;

Explanation:

First, we will create the class and then under the class, we have to define the main method. Now, we will create the objects of the scanner class. Then, we will input a word. Now, we have to use a for loop. In the for loop, we will extract every character from the given string using charAt() method and we will store it in ch variable. Now, if we convert the character ch to integer(i.e. int), we will get the ASCII value of the character.In this way, the program works.

Answered by Lueenu22
0

Explanation:

Here is your code.

< hr/ ><hr/>

import java.util.*;

class x

{

static void main()

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the name: ");

String s = sc.nextLine();

int len=s.length();

for(int i=0;i<len;i++)

{

char ch=s.charAt(i);

int ascii=(int)ch;

System.out.println("ASCII value of "+ch+" is: "+ascii);

}

}

}

< hr/ ><hr/>

Explanation:

First, we will create the class and then under the class, we have to define the main method. Now, we will create the objects of the scanner class. Then, we will input a word. Now, we have to use a for loop. In the for loop, we will extract every character from the given string using charAt() method and we will store it in ch variable. Now, if we convert the character ch to integer(i.e. int), we will get the ASCII value of the character.In this way, the program works.

Similar questions