Skip to content

Commit 32eee49

Browse files
authored
Add files via upload
Write a java code to find the sum of the given numbers Input: "asdf1qwer9as8d7" output: 1+9+8+7 = 25
0 parents  commit 32eee49

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

FindSumOfNumbersApproachASCII.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package powerJavaLearning;
2+
3+
public class FindSumOfNumbersApproachASCII {
4+
5+
public static void main(String[] args) {
6+
String input ="asdf1qwer9as8d7";
7+
char[] array = input.toCharArray();
8+
int sum=0;
9+
for (int i = 0; i < array.length; i++) {
10+
if((int)array[i]>=48 && (int)array[i]<=57) {
11+
sum+=Character.getNumericValue(array[i]);
12+
}
13+
System.out.println("integer " +Character.getNumericValue(array[i]));
14+
}
15+
System.out.println("Sum of Integers "+ sum);
16+
}
17+
}

0 commit comments

Comments
 (0)