Computer Science, asked by SohamKundu012, 1 year ago

How to write a program in JAVA to print the sum of ASCII values of a particular word input ?​

Answers

Answered by dynamogirl
9

\huge\red{Answer}

1) * C Program To Find the Sum of ASCII values of All Characters in a.

2) * given String.

3) #include <string.h>

4) int sum = 0, i, len;

5) char string1[100];

6) printf("Enter the string

7) ("%[^\n]s", string1);

8) len = strlen(string1);

Thanks!!!

______________⭐⭐⭐⭐

Answered by Anonymous
6

\mathbb{\underline{CODE}}

import java.util.*;

class ASCII_adding

{

public void main()

{

Scanner sc=new Scanner(System.in);

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

String s=sc.next();

int l=s.length();

int S=0;

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

{

char ch=sc. charAt(i);

S=S+(int)(ch);

}

System.out.println("Sum="+S);

}

}

▶ The word's length has to be found .

▶ Then we will run a for-loop .

▶ Then add up the ASCII values by converting the character to integers.

▶ The character function is used here to locate the position of a particular character in the word .

Similar questions