charAt, 함수 만들기

권나영·2020년 10월 22일

융합 프로그래밍

목록 보기
1/2

💋 charAt

class 안에 s가 몇 개 들어가 있는지 보는 코드

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count = 0;
		String a = "class";
		
		for(int i=0; i<a.length(); i++) {
			if(a.charAt(i)=='s') 
				count++;
		}
	System.out.println(count);
	}

class의 0번째 인덱스의 문자 받아오는 코드

public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count = 0;
		String a = "class";
		
		System.out.println(a.charAt(0));
	}

💋 함수 만들기

3 넣으면 4 출력해주는 함수 만들기

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		increase(3);
	}
	
	static void increase(int m) {
		m+=1;
		System.out.println(m);
	}
profile
나영

0개의 댓글