• 메모리 사용 영역
	○ 
• java 정규표현식
	○ import util.regex.Pattern()

• java 입출력 메소드 관련
	○ import java.util.Scanner;
	○ throws IOException{}
		§ ->입력상황 발생시 예외처리 반드시 필요
	○ Scanner sc=new Scanner(System.in);
	○ int a,b;
	a=sc.nextInt();
	b=sc.nextInt();
	System.out.println(a+"@"+b);
		->입력 10 20
		->출력 10@20
	○ char(문자 1개) 입력받는경우
		§ char ch=(char)System.in.read();
		§ read() -> inputstream에서 1byte 만 읽는 메소드
		chara1,b1;
		a1=(char)System.in.read();
		b1=(char)System.in.read();
		System.out.println(a1+" dfdf"+b1);
		§ 이런식으로 하면 안됨-> read()는 \n(엔터)도 문자로 치기 때문에 [a dfdf]출력됨
		§ 
	○ 문자 여러개 입력받고싶은경우
		
		        Scanner sc=new Scanner(System.in);
		        char a,b;
		        String str;
		        str=sc.nextLine();
		        a=str.charAt(0);
		        b=str.charAt(3);
		        System.out.println(a+" ,  "+b);
		        sc.close();
	○ next() 와 nextline()의 차이
		§ nextLine(): 문자열 리턴인데 \n포함하는 한 line을 읽고 \n 버린 나머지만 리턴
		int num = sc.nextInt();

sc.nextLine();
String str = sc.nextLine();
->이런식으로 버퍼 정리 필요
§ next(): 문자열 리턴, 공백과 엔터 전까지 입력받은 문자열 반환, 엔터(\n)을 안버림->Sytem.out.nextLine();으로 엔터 버려줘야함
○ ==> nextLine은 엔터로 구분, next는 공백,엔터 구분..!!!!!
• 문자열 파싱하기
○ import java.util.StringTokenizer;
○ String tokenizer st=new stringtokenizer(str," ",false);
§ 공백 기준으로 문자열 분리
§ (str)만 인수로 주면 공백 기준으로 단어별 분리
○ str.nextToken()-> 객체에서 다음 토큰 반환
○ hasMoreTokens()-> 남아있는 토큰 있으면 true, 아니면 false
○ countTokens()-> 총 토큰 개수 리턴
• 아스키코드 외울것
○ 숫자 0=>48
○ enter=>13
○ 대문자 A=>65
○ 소문자 a=>97
• read() 메소드
○ 앞에서부터 1바이트씩 읽어오는 메소드
int a1=System.in.read() -48;
System.out.println(a1);
int a2=System.in.read() -48;
System.out.println(a2);
System.out.println(System.in.read()-48);
○ 입력-> 324
○ 출력-> 3
2
4
• string을 int arr로 변환하기
String a="01234";
int arr[]=new int[5];
for(int i=0;i<a.length();i++){
arr[i]=a.charAt(i)-48;
System.out.print(arr[i]+",");

• System.in.read();
	○ 버퍼의 한 바이트 버리는데 사용
• a.compareTo(b)
	○ a가 b보다 크면 1, 같으면 0, 작으면 -1


• string은 " ABCD"
	○ java에서 string은 불변값
	○ 값 바꾸고 싶으면 
		§ char[] arr1=str.toCharArray();
		char[3]='a'
		str=String.valueOf(arr1);
		§ substring()
			
• 공백제거
	○ String result1 = str1.trim();-> 맨앞, 맨뒤 공백만 제거
	○ String.replace(char, char): 첫번째 인자의 문자를 찾고, 두번째 문자로 변환해 줍니다.
	○ String.replaceAll(String, String): 첫번째 문자열을 찾고, 두번째 문자열로 변환
	○ String.replaceFirst(String, String): 단, 한번만 첫번째 인자의 문자를 찾고, 두번째 문자로  변환
• 문자열 자르기
	○ substring(index)->index 부터 끝까지 반환
	○ substring(index1,index2)-> index1부터 index2 전까지(미포함)반환
• 정규표현식
	○ import java.util.regex.Matcher;
	○ import java.util.regex.Pattern;
	l 
	
	○ 
	
	->한글, 숫자, 영어 소문자, 대문자, 띄어쓰기를 제외하고 다른 문자 제거=특수문자 제거
• 문자열 거꾸로 뒤집기
	○ StringBuffer 클래스(기본 java.lang에있음)
	○ String StringBuffer sb=new StringBuffer();
	○ sb.append(str);
	○ sb=sb.reverse();
	○ String result=sb.toString();  ->stringbuffer형에서 string으로 형변환
• 문자열 비교-> a.equals(b)로 비교해야함 ==쓰면 stack에 참조하는 변수 자체가 같은 경우만 같다고 침
• Main에 static을 사용하는 이유
	○ static은 java 프로그램이 실행하기 전에 static 함수나 static 변수를 첫 단계로 메모리에 올려 프로그램을 실행 (static이 실행시 1순위)
	○ 프로그램이 종료될 때까지 사라지지 않음
	○ main함수가 실행되기 위해서는 메모리에 미리 올라가함.
	○ 메모리에 올라가있지 않으면, 시작점인 main() 메소드를 호출하려고 하는데 메모리에는 main이 없기 때문에 실행X
	○ 그래서 main 메소드는 누군가 호출하기 전에 미리 메모리에 있어야 하기 때문에 static을 붙임
• SetName, this용법
	○ setName 메소드 내부에 사용된 this는 Animal 클래스에 의해서 생성된 객체를 지칭한다. 만약 Animal cat = new Animal() 과 같이 cat이라는 객체를 만들고 cat.setName("boby") 와 같이 cat객체에 의해 setName 메소드를 호출하면 setName 메소드 내부에 선언된 this는 바로 cat 객체를 지칭한다.

만약 Animal dog = new Animal()로 dog 객체를 만든 후 dog.setName("happy") 와 같이 호출한다면 setName 메소드 내부에 선언된 this는 바로 dog 객체를 가리킨다.

• 메소드에 값(primitive type)을 전달하는 것
	○ 그 메소드 안의 로컬 변수로서만 활용됨-> main함수에 적용x
	○  객체(reference type)를 전달해야함
• this는 자신을 main에서 부른 객체에 접근할 때 사용된다.
• 


• substring(0,1)하면 string형태로 반환되고 첫번째 글자만 따와짐
• import java.util.Arrays에서 array출력하고 싶으면(문자열 형태)
	○ System.out.print(Arrays.toString(array명));
• next(), nextInt() 둘다 공백전까지 읽고 공백 버림
• Math.random()함수 사용법
	○ (int) Math.random() * (최댓값-최소값+1) + 최소값
		§ 1부터 100까지 정수 랜덤
• for(int num: nums){
            num=(int)(Math.random()*(100))+1;
            System.out.print(num+"..");}

->불가능: for each를 통해서 가져온 값은 배열 값을 복사해서 가져왔기 때문에 원 배열 요소 수정 불가능!

0개의 댓글