본문 바로가기

JAVA/쓸만한 코드

함수//입력공간 찾기

	Scanner sc = new Scanner(System.in);
	String student[][] = new String [20][4];
	int choice;
	
	for (int i = 0; i < student.length; i++) {
		for (int j = 0; j < student[i].length; j++) {
			student[i][j] = "";
		}
	}
    while(true) {
	System.out.println("-----------------메뉴");
	System.out.println("1. 학생 정보 추가");
    
    switch(choice) {
		case 1://학생추가
			insert(student);
    }
    
    }
    static void insert(String student[][]) {// 학생 정보 추가
	Scanner sc = new Scanner(System.in);
	
	int findIndex = -1;
	for (int i = 0; i < student.length; i++) {
		if(student[i][0].equals("")) {	//0 1 2
			findIndex = i;
			break;
		}
	}
	System.out.println("findIndex:"+findIndex);
    
    System.out.println("이름 : ");
	String name = sc.next();
    
	student[findIndex][0] = name;
    
    System.out.println("입력완료"+student[findIndex][0]);
}