Count the number of words in a string array

Source: Internet
Author: User

public class _z {

public static void Main (String a[]) {
String x[]=new string[]{"Every", "Day", "we", "should", "Smile", "on", "the", "people", "Around", "Us"};
int word_w=0;
int word_or=0;
int word_length3=0;
for (int i=0;i<x.length;i++) {
System.out.print (x[i]+ "");
}
System.out.println ();
for (int i=0;i<x.length;i++) {
if (x[i].substring (0,1). Equals ("W") | | X[i].substring (0,1). Equals ("W")) {
word_w++;
}
}
for (int i=0;i<x.length;i++) {
if (X[i].indexof ("or")!=-1)
word_or++;
}
for (int i=0;i<x.length;i++) {
if (X[i].length () ==3)
word_length3++;
}
System.out.println ("The words with the letter W begin with" +word_w+ ");
System.out.println ("The word contains" or "string words have" +word_or+ ");
System.out.println ("The word with a length of 3 has a" +word_length3+ ");
}
}

Count the number of words in a string array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.