"Braund, Mr. Owen Harris",
			    "Cumings, Mrs. John Bradley (Florence Briggs Thayer)",
			    "Heikkinen, Miss. Laina",
			    "Futrelle, Mrs. Jacques Heath (Lily May Peel)",
			    "Allen, Mr. William Henry",
			    "Moran, Mr. James",
			    "McCarthy, Mr. Timothy J",
			    "Palsson, Master. Gosta Leonard",
			    "Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",
			    "Nasser, Mrs. Nicholas (Adele Achem)",
			    "Sandstrom, Miss. Marguerite Rut",
			    "Bonnell, Miss. Elizabeth",
			    "Saundercock, Mr. William Henry",
			    "Andersson, Mr. Anders Johan",
			    "Vestrom, Miss. Hulda Amanda Adolfina",
			    "Hewlett, Mrs. (Mary D Kingcome) ",
			    "Rice, Master. Eugene",
			    "Williams, Mr. Charles Eugene",
			    "Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele)",
			    "Masselmani, Mrs. Fatima",
			    "Fynney, Mr. Joseph J",
			    "Beesley, Mr. Lawrence",
			    "McGowan, Miss. Anna",
			    "Sloper, Mr. William Thompson",
			    "Palsson, Miss. Torborg Danira",
			    "Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)",
			    "Emir, Mr. Farred Chehab",
			    "Fortune, Mr. Charles Alexander",
			    "Dwyer, Miss. Ellen",
			    "Todoroff, Mr. Lalio"


위의 데이터에서 M을 가지고 있는 아이템의 수를 출력하시오



public class DataSetTest {

	public static void main(String[] args) {
		
		String dataset[] = {
			    "Braund, Mr. Owen Harris",
			    "Cumings, Mrs. John Bradley (Florence Briggs Thayer)",
			    "Heikkinen, Miss. Laina",
			    "Futrelle, Mrs. Jacques Heath (Lily May Peel)",
			    "Allen, Mr. William Henry",
			    "Moran, Mr. James",
			    "McCarthy, Mr. Timothy J",
			    "Palsson, Master. Gosta Leonard",
			    "Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",
			    "Nasser, Mrs. Nicholas (Adele Achem)",
			    "Sandstrom, Miss. Marguerite Rut",
			    "Bonnell, Miss. Elizabeth",
			    "Saundercock, Mr. William Henry",
			    "Andersson, Mr. Anders Johan",
			    "Vestrom, Miss. Hulda Amanda Adolfina",
			    "Hewlett, Mrs. (Mary D Kingcome) ",
			    "Rice, Master. Eugene",
			    "Williams, Mr. Charles Eugene",
			    "Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele)",
			    "Masselmani, Mrs. Fatima",
			    "Fynney, Mr. Joseph J",
			    "Beesley, Mr. Lawrence",
			    "McGowan, Miss. Anna",
			    "Sloper, Mr. William Thompson",
			    "Palsson, Miss. Torborg Danira",
			    "Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)",
			    "Emir, Mr. Farred Chehab",
			    "Fortune, Mr. Charles Alexander",
			    "Dwyer, Miss. Ellen",
			    "Todoroff, Mr. Lalio"
			};
		
		int cnt = 0;
		
		for (int i = 0; i < dataset.length; i++) {
			
			if (dataset[i].indexOf("M") > 0) {
		
				cnt++;
			}
		}
		System.out.println("M의 개수 : " + cnt + "개");

	}

}



결과

M의 개수 : 26개

Leave a comment