I'm trying to sum the Ascii values of different strings while adhering to the following instructions:
Create two overloaded methods. One that will give the sum of the ascii values of each character in a String and another which will produce the sum of the ascii values of two Strings.
Using the methods that I already wrote, how could I print out the sum in my main? Thanks!
public class Exam3Question2
{
public static int sumAscii(String Input)
{
String s = Input;
int sum = 0;
for (int i = 0; i < s.length(); i++)
{
sum+= (int)s.charAt(i);
}
return sum;
}
public int sumAscii( String Input1, String Input2)
{
int sum = sumAscii(Input1) + sumAscii(Input2);
return sum;
}
public static void main(String[] args)
{
Exam3Question2 c = new Exam3Question2();
Scanner in = new Scanner(System.in);
String word;
System.out.println("Enter some text");
word = in.nextLine();
sumAscii(word);
int sum1 = c.sumAscii(Input1);
int sum2 = c.sumAscii(Input1, Input2);
int sum3 = sum1 + sum2;
System.out.println("The sum of the two strings is: " + sum3);
}
}