Wednesday, 11 November 2020

Write a Program in Java to accept a set of any 10 characters. Calculate and print the sum of ASCII codes of the characters.

 import java.util.*;

public class ASCII_Sum

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

char ch; int i,sum=0;

for(i=1;i<=10;i++)

{

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

    ch=in.next().charAt(0);

    sum=sum+(int)ch;

}

System.out.println("The Sum of ASCII values of the entered Characters is: "+sum);

}

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...