본문 바로가기

java

(5)
자바-맵,집합,상수 집합 맵은  키(key)와 값(value)을 한 쌍으로 갖는 자료형 맵의 내장함수더보기import java.util.HashMap; public class Sample {     public static void main(String[] args) {         HashMap map = new HashMap();         map.put("people", "사람");         map.put("baseball", "야구");        System.out.println(map.get("people")); // "사람" 출력        System.out.println(map.containsKey("people")); // true 출력        System.out.println(map.key..
자바- StringBuffer,배열,리스트 StringBuffer는 문자열을 추가하거나 변경할 때 주로 사용하는 자료형 StringBuffer의 내장함수 append,insert,subsring더보기StringBuffer sb = new StringBuffer(); sb.append("jump to java"); sb.insert(0, "hello ");String result = sb.toString(); System.out.println(result); // "hello jump to java" 출력 System.out.println(sb.substring(0, 4));//"Hell"출력배열(array)은 숫자나 문자열의 집합. 배열은 자료형 바로 옆에 [] 기호를 붙인다. 길이 설정+ 접금더보기String[] weeks = new Strin..
자바-문자열 String a ="Happy Java"의 형식을 가지는 문자열문자열 내장 메서드equals 메서드는 문자열 2개가 같은지를 비교하여 결괏값을 리턴더보기String a = "hello";String b = "java";String c = "hello";System.out.println(a.equals(b)); // false 출력System.out.println(a.equals(c)); // true 출력indexOf는 문자열에서 특정 문자열이 시작되는 위치(인덱스값)를 리턴더보기String a = "Hello Java";System.out.println(a.indexOf("Java"));  // 6 출력contains 메서드는 문자열에서 특정 문자열이 포함되어 있는지 여부를 리턴더보기String a =..
자바-연산자,Math 자바 연산자  랜덤값(0~1사이)Math.random()static double random() 0.0 이상 1.0 미만의 범위에서 임의의 double형 값을 하나 생성하여 반환함.Random rand =new Random();int index = rand.nextInt(index);index는 절대값Math.abs(param)static double abs(double a) static double abs(float a)static double abs(int a)static double abs(long a)전달된 값이 음수이면 그 값의 절댓값을 반환하며, 전달된 값이 양수이면 인수를 그대로 반환함.Math.ceil(param)static double ceil(double a)전달된 double형 값의 ..
자바-변수(생성규칙& 숫자,불,문자) 1. 변수:단 하나의 값을 저장할 수 있는 메모리 공간 생성 규칙변수명은 숫자로 시작할 수 없다._와 $ 이외의 특수 문자는 사용할 수 없다.int, class, return 등 자바의 키워드는 변수명으로 사용할 수 없다.더보기점프 투 자바자바의 키워드 알아 두기변수명을 정할 때 반드시 피해야 하는 자바의 키워드는 다음과 같다.Copyabstract continue for new switchassert default goto package synchronizedboolean do if private thisbreak double implements protected throwbyte e..