Write a Java Program to find ASCII values of String Characters with an example. In this java example, we used the String codePointAt function to return the character’s ASCII code.
import java.util.Scanner;
public class ASCIIValuesOfStringChars {
private static Scanner sc;
public static void main(String[] args) {
String asciistr;
int i = 0;
sc= new Scanner(System.in);
System.out.print("\n Please Enter any Sentence for ASCII Codes : ");
asciistr = sc.nextLine();
while(i < asciistr.length())
{
System.out.println("The ASCII Value of " + asciistr.charAt(i) +
" Character = " + asciistr.codePointAt(i));
i++;
}
}
}

Java Program to find ASCII values of String Characters using For loop
import java.util.Scanner;
public class ASCIIValuesOfStringChars1 {
private static Scanner sc;
public static void main(String[] args) {
String asciistr;
int i;
sc= new Scanner(System.in);
System.out.print("\n Please Enter any Sentence for ASCII Codes : ");
asciistr = sc.nextLine();
for(i = 0; i < asciistr.length(); i++)
{
System.out.println("The ASCII Value of " + asciistr.charAt(i) +
" Character = " + asciistr.codePointAt(i));
}
}
}

It is another Java example to find ASCII values of Characters in a string. Here, we are typecasting character to an integer, which will show you the ASCII value of that character.
import java.util.Scanner;
public class ASCIIValuesOfStringChars2 {
private static Scanner sc;
public static void main(String[] args) {
String asciistr;
int i;
sc= new Scanner(System.in);
System.out.print("\n Please Enter any Sentence for ASCII Codes : ");
asciistr = sc.nextLine();
for(i = 0; i < asciistr.length(); i++)
{
char ch = asciistr.charAt(i);
int num = (int) ch;
System.out.println("The ASCII Value of " + ch +
" Character = " + num);
}
}
}
