본문 바로가기
728x90
반응형

전체 글565

[Java] 29. Test1 (다음 결과가 나오도록 한곳만 수정하기) package chap11; /* * 다음 결과가 나오도록 한곳만 수정하기 * [결과] * basket * basketball */ public class Test0321_1 { public static void main(String[] args) { String str = "base"; //basket System.out.println(str.replace('e','k')+"et");//basket str += "ball"; System.out.println(str);//basketball } } 2022. 3. 25.
[Java] 29. 기본 API (숫자 <= 문자열) package chap11; //숫자 2022. 3. 25.
[Java] 29. 기본 API (String.format) package chap11; /* * String.format 메서드 : 숫자,문자 => 형식화된 문자열 변경 * => 형식화 문자 사용가능 메서드 : %d, %c, %f * => 클래스메서드 (클래스메서드명.format으로 사용가능) * => System.out.printf() 메서드와 사용방법이 동일. */ public class StringEx4 { public static void main(String[] args) { //%f : 실수 출력 형식문자 String sf = String.format("%.2f", 0.142); //0.14 System.out.println(sf); //%.2f : 소숫점이하 2자리로 실수 출력 sf = String.format("%.2f", 0.145); //0.1.. 2022. 3. 25.
[Java] 29. 기본 API Exam2 (count 메서드 구현하기) package chap11; /* * count 메서드 구현하기 * int count(문자열소스,찾는 문자열) : 문자열 소스에서 찾는 문자열의 갯수를 리턴 */ public class Exam2 { public static void main(String[] args) { System.out.println(count("12345AB12AB345AB","12")); //2 System.out.println(count("12345AB12AB345AB","AB")); //3 System.out.println(count("12345","6")); //0 } private static int count(String s1, String s2) { //12345AB12AB345AB //12 int cnt = 0, i.. 2022. 3. 25.
728x90
반응형