본문 바로가기
개발/자바

자바 2차원 배열

by kakk789 2022. 1. 10.
package for_IF;

public class for_IF {

	public static void main(String[] args) {

		String id = "cccc";
		String pw = "3333";
		
		String[][] doubleArray = {
			{"aaaa", "1111"}, //[0][0], [0][1]
			{"bbbb", "2222"}, //[1][0], [1][1]
			{"cccc", "3333"}  //[2][0], [2][1]
		};

		boolean isLogined = false;
		for(int i=0;i<doubleArray.length;i++) {
			String[] current = doubleArray[i]; 
            			//--> doubleArray의 0,1,2번째 배열을 current 배열에 담는 것(덮어씀)
			if(id.equals(current[0]) && pw.equals(current[1]))
			{			
				isLogined = true;
				break;
			}
		}		
		if(isLogined) {System.out.println("하이요");}
		else {System.out.println("누구?");}	
	}
	
	
}
반응형

댓글