본문 바로가기

JAVA/String class4

String 예제(2) package strings; public class Quiz02 { public static void main(String[] args) { // Quiz // It is a fun java programming // - 위 문장에서 공백을 제외한 총 길이, a와 g의 개수를 출력 String ex = "It is a fun java programming"; int aCnt = 0, gCnt = 0, total; String replaceEx = ex.replace(" ", ""); total = replaceEx.length(); for (int cnt = 0; cnt < replaceEx.length(); cnt++) { if (ex.charAt(cnt) == 'a') aCnt++; else if .. 2022. 7. 24.
String 예제(1) package strings; public class Quiz01 { public static void main(String[] args) { // Quiz1 // Have a nice day Have a nice day Have a nice day // 위 문자열에서 a의 위치를 '저장하여' 출력 // 결과 : 1, 5, 13 ,17, 21, 29, 33, 37, 45 String ex = "Have a nice day Have a nice day Have a nice day"; int array[] = new int[ex.length()]; int arrayCnt = 0; for (int cnt = 0; cnt < ex.length(); cnt++) if (ex.charAt(cnt) == 'a') a.. 2022. 7. 21.
String(2) package strings; public class StringClass2 { public static void main(String[] args) { // String.trim // - 문자열의 옆구리(좌우측)에 공백을 제거해준다. String str = " Have a nice day "; System.out.println(str); String strTrim = str.trim(); System.out.println(strTrim); // split // 파라미터에 입력된 해당 값을 문자열로부터 제거해준다. // 제거작업을 거치면서 별도의 문자열로 분리된다. // // 향샹 for문 //for (자료형 변수 : 데이터) { //종속문장; //} // - 데이터가 끝날때까지 변수에 담아 종속문장을 .. 2022. 7. 21.
String(1) package strings; import java.util.Scanner; public class StringClass { public static void main(String[] args) { // String // string은 int, short 등 기본자료형이 아닌 클래스다. // string.을 통해서 string 클래스가 보유한 다양한 기능을 지원받을 수 있다. Scanner sc = new Scanner(System.in); String data1; String data2 = new String(); // 두 문장은 같은 의미이며 new String()생략 가능 // char형 배열의 단일문자 모음을 new String()을 통해 문자열로 변경이 가능하다. char datas[] = {'.. 2022. 7. 21.