Java中判斷一句英文中有多少個以p開頭的單詞
package Pak01;
public class TestString {
public static void main(String[] args) {
String s="peter piper picked a peck of pickled peppers";
System.out.println(s);
//將這些單詞以空格進行拆分放進一個String型別的字串數組裡
String[] words=s.split(" ");
int count=0;
for(int i=0;i<words.length;i++) {
String word=words[i];
//判斷每個單詞的首字母
if(word.charAt(0)=='p') {
count++;
}
}
System.out.println(count);
}
}
相關推薦
Java中判斷一句英文中有多少個以p開頭的單詞
package Pak01; public class TestString { public static void main(String[] args) { String s="peter piper picked a peck of pickled p
Java總雜湊表的運用,判斷一個數組中是否存在相同的元素之間的距離在k以內!
Check if a given array contains duplicate elements within k distance from each other 用雜湊表,複雜度O(n),
C#實現如何判斷一個數組中是否有重複的元素
如何判斷一個數組中是否有重複的元素 實現判斷陣列中是否包含有重複的元素方法 這裡用C#程式碼給出例項 方法一:可以新建一個hashtable利用hashtable的Contains方法進行查詢 1 /// <summary> 2 /// Hash
將一句英文句子中多餘的空格去掉
#include<iostream> #include<string> using namespace std; int main(){ string str; int i,len,flag=0; getline(cin,str);
C++實現一句英文句子中的單詞逆置
去騰訊面試的時候被問到這個題,當時說了兩種方法,但是都需要移動元素,且需要輔助空間,面試官不太滿意。其實這道題不難,只能怪我太笨嘍。後來面試官告訴了我答案,確實是不錯的方法,只用了一點小技巧就很容易的實現了,回來之後我就用程式碼實現了下,寫到這裡分享一下,也當是給自己長記性
2013北郵java教程第4次實驗統計一句英語中母音字母的個數
編寫一個JAVA程式,統計一句英語中母音字母的個數。 放程式碼: import java.util.*; public class Summary {/*** @param args* @author Chenxingman*/public static void main
JS判斷一個數組中是否有重複值的三種方法
參考 http://superivan.iteye.com/blog/1131328 var ary = new Array("111","22","33","111"); var s = ary.
java 判斷一個數組中的數值是否連續相鄰
* 判斷一個數組中的數值是否連續相鄰 * 滿足以下條件: * 1.0是例外可以反覆出現 0可以通配任何字元 * 2.相同的數值不
總有一句英文,能夠溫暖到你!
art from 技術分享 ant when my life png people webp I will make you happy when you are depressed. I will make you delighted when you a
mysql資料庫的簡單增刪改查,合併欄位,拼接字元操作,用java完成將一張表中的查詢結果合併存入另一張表的指定欄位
首先問題描述:我現在有兩個表,一個表是關鍵詞,一個表是含有關鍵詞的標籤,需要做的就是在關鍵詞表中新建一個標籤欄位,把包含該關鍵詞的全部標籤存入其中。比如關鍵詞是Java,標籤可能有Java開發,Java後臺等。我這裡關鍵詞有4000個,標籤有40000個,我用了小段java程式碼+sql的函式就完成
java 判斷一個數組是否有重複值
import java.util.HashSet; public class test { /** * @param args */ public stat
如何判斷一個數二進位制中“1”的個數
在這裡我們以數字“7”為例(數字“7”的二進位制為“111”,有三個“1”),提供兩種方法來判斷一個數中二進位制中“1”的 個數! 1.使用移位操作符(右移操作) 讓二進位制的每一位&(邏輯與)1,如果得到的結果為數字“1”,則二進位制數該位有一個“1”。
C#中怎麼判斷一個數組中是否存在某個陣列值
(1) 第一種方法: int[] ia = {1,2,3}; int id = Array.IndexOf(ia,1); // 這裡的1就是你要查詢的值 if(id==-1) // 不存在 else // 存在 (2) 第二種方法: string[] strArr =
Python學習中的一句笑話
尾遞迴呼叫時,如果做了優化,棧不會增長,因此,無論多少次呼叫也不會導致棧溢位。 遺憾的是,大多數程式語言沒有針對尾遞迴做優化,Python直譯器也沒有做優化,所以,即使把上面的fact(n)函式改成尾遞迴方式,也會導致棧溢位。 from:http://www.liaoxu
Java實現統計一篇文章中每個單詞出現的次數
import java.io.File; import java.io.FileReader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import jav
java記——統計一串字元中每個字母出現的個數
程式程式碼: import java.util.Scanner; public class Kn { public static void main(String[] args){ Scanne
Java中對一個數組中的數字進行排序
package javatest;public class Test5 { public void Arr() { int arr[] = { 178, 177, 182, 179, 185, 175, 186, 17, 181, 180 }; int i, j; Sys
JQuery中判斷一個元素下面是否有內容或者有某個標籤的判斷程式碼
如下,怎麼判斷ul標籤內是否有內容?(下面的ul沒有內容) if($("ul[class$='XXX']").find("li").length==0){//如果class中包含“XXX”的ul標
使用jQuery判斷一個數組中是否包含某個值
1、當需要在前端為陣列去重的時候,可以使用jQuery的inArray方法來判斷。 2、具體操作如下: var array = ['a','ab','abc']; $.inArray('abc',array);下標從0開始,若結果為-1則表示此陣列中不存在這個值。
Java (1)尋找一堆數字中只出現一次的數字 (2)統計一堆檔案字尾名共有幾種型別(即統計一堆數字中出現過那幾個數字)
//*************(1)尋找一堆數字中只出現一次的數字*********** package cn.nrsc.test1; import java.util.ArrayList; //設計一個方法,傳入一個int型別陣列,輸出這個陣列中只出現一次的數字。