0

Hello...how do i count characters in the sentence...example i write in console with space or .?-() then it output us count

20th Nov 2016, 6:37 PM
Hasim Hasimov
Hasim Hasimov - avatar
5 Antworten
+ 1
It depends. If you need an algorithm, i'll to show you, but else you can use the length function. Exemple: String sentence = "Hello World"; int length = sentence.length(); Else, if you need an algorithm, call this function in your main and pass sentence in parameter. :) public static int length(String str) { int i = 0; str += '\n'; while(str.charAt(i) != '\n') { i++; } return i; }
20th Nov 2016, 8:43 PM
Volts
Volts - avatar
+ 1
Oops, it is a String. ;)
21st Nov 2016, 12:48 PM
Volts
Volts - avatar
0
thank i'll try it
21st Nov 2016, 3:16 AM
Hasim Hasimov
Hasim Hasimov - avatar
0
sorry i dont know str variables in lenght method
21st Nov 2016, 12:40 PM
Hasim Hasimov
Hasim Hasimov - avatar
0
thank
21st Nov 2016, 12:51 PM
Hasim Hasimov
Hasim Hasimov - avatar