139k views
5 votes
Write a method that determines the total number of chars in each string of an array.

User Oozzal
by
8.0k points

1 Answer

3 votes
The total number of chars in each string is basically the size of each string.

Using JAVA:

String[] arr = {"hello", "my", "name", "is", "Felicia"}; int count = 0; for(int i = 0; i < arr.length; i++) { count = count + arr[i].length(); System.out.println("Characters in " + arr[i] + ": " + count); }

Output:
Characters in hello: 5
Characters in my: 7
Characters in name: 11
Characters in is: 13
Characters in Felicia: 20


User DuckPuppy
by
8.3k points