JAVA: char배열의 길이를 입력할 때마다 다르게 하려면??
조회수 468회
계좌개설 후 ID가 맞는지 비교하려고 하는 코드를 짜려고
Account 객체를 만들었는데요.
Account 배열을 생성 후
class Account {
private double annualInterestRate = 0;
private Date dateCreated = new Date();
private static char[] name = new char[20];
private static char[] id = new char[10];
private static int passwd = 0;
char[] address = new char[100];
char[] phone = new char[13];
private long balance = 0;
``
Account() { }
Account(char[] name, char[] id, int passwd, char[] address, char[] phone, long balance) {
this.name = name;
this.id = id;
this.passwd = passwd;
this.address = address;
this.phone = phone;
this.balance = balance;
}
예를 들어 이름을 입력할 때,,
'홍길동'은 ㅎ ㅗ ㅇ ㄱ ㅣ ㄹ ㄷ ㅗ ㅇ 총 9길이이고,
'선우정아'는 ㅅ ㅓ ㄴ ㅇ ㅜ ㅈ ㅓ ㅇ ㅇ ㅏ 총 10길이입니다.
이 처럼 입력할 때마다 배열의 길이를 다르게 할 수 있을까요??
char[] newID = new char[10];
for(int i=0; i<newID.length; i++) {
newID[i] = s.next().charAt(0);
}
int newPasswd = s.nextInt();
}
// 비교test
public void compareAcc(char[] inID) {
int k;
for(k=0; k<acc.length; k++) {
if( !inID.equals(acc[k])) {
System.out.println("there isn't ID"); break;
} else {
System.out.println("just pass");
index = k;
}
}
}
댓글 입력