السلآم عليكم و رحمة الله و بركاتهـ ،،
اشحآلكمـ..
الموضوع من عنوانه كيف أحسب عدد الكلمات ف البرآغراف بون مآ أحسب الستآر
للعلم الستآر تدل ع بداية براغراف يديد
مثال:
* hello this is java.
المفروض عدد الكلمات يطلع لي 4
int star_position = 0 ;
int space_position = 0;
int count_word = 0 ;
String word = "" ;
do
{
star_position = s.indexOf ("* ") ;
space_position = s.indexOf(" ");
if(star_position != -1){
s= s.substring(star_position+1);
System.out.println("in star:"+s);
space_position = s.indexOf(" ");
System.out.println(space_position);
}
if (space_position != -1) //If there is no space in the string
{
word = s.substring (0 ,space_position) ;
System.out.println(word);
count_word++ ;
s = s.substring (space_position + 1, s.length ()) ;
}
} while (s.equals ("") == false && space_position != -1);
System.out.println ("The string contains " + count_word + " words.") ;