I am writing this program for school work that asks the user to input a sequence of letters and numbers and determine whether it is a digit or not.
My teacher wants me to add up the characters that are digits(numbers) and output it as "Your numbers added up together are: place added number here" and output the letters are a string saying "These are your letters: *place letters here."
I think I got the code right that determines whether it is a digit or not but how do I end up adding them? I tried using an if statement that checked if Character.isDigit is true but I keep getting errors and I think I'm writing it totally wrong. Any response would be greatly appreciated.
Here is my code:
import java.util.*;
import java.util.Scanner;
public class MyClass
{
public static void main(String args[])
{
int sum1 = 0;
String stringFull = "";
boolean isTrue = Character.isDigit(string1.charAt(i));
Scanner getString = new Scanner(System.in);
System.out.println("Please enter a sequence of letters: ");
String string1 = getString.nextLine();
for(int i = 0; i < 5; i++)
{
if (Character.isDigit(string1.charAt(i)))
{
sum1 += Character.getNumericValue(string1.charAt(i));
} else {
stringFull += string1.charAt(i);
}
if (isTrue)
{
System.out.println(sum1 * sum1);
}
}
}
}
boolean isTrue = Character.isDigit(string1.charAt(i));,idoesn't exist yet.