S
S
Slavon72021-10-30 21:43:44
Java
Slavon7, 2021-10-30 21:43:44

How to count each element?

It is necessary to count each element of the string, that is, Obram = 5 Obramnik = 8, etc.
I count the entire string together, that is, Obram + Obramnik + Ob ... = 22
I can’t think of (rather, I don’t even know) a condition that would solve my problem
If you know how to implement it, then it is not necessary to write the code for me, you can simply suggest

public class main {
public static void main(String[] args) {

String[] arrString = new String[] {"Obram","Obramnik" ,"Obramovich"};
int count = 0;
for(int i = 0;i < arrString.length;i++) {
System.out.println(arrString[i]); // Output all strings
for(int j = 0;j < arrString[i].length();j++) { // Count all letters
count++;
System.out.println(count); //
}
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-10-30
@Slavon7

Move the declaration of the counter variable to the body of the outer loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question