JAVA: To change the length of the char array every time you enter it?

Asked 2 years ago, Updated 2 years ago, 23 views

After opening an account, I want to make a code to compare if the ID is correct.

You created an Account object.

Create an Account Array and

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;
}

For example, when you enter a name, you can enter,,

Hong Gil-dong is 9 lengths in total.

"Sunwoo Jung-ah" is a total of 10 lengths.

Is it possible to change the length of the array each time you type it like this?

    char[] newID = new char[10];
    for(int i=0; i<newID.length; i++) {
        newID[i] = s.next().charAt(0);
    }

    int newPasswd = s.nextInt();




}

// Comparison 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;
            }
        }

}

java

2022-09-21 12:16

1 Answers

Create a list and stretch it variably using the add() method, and if you need an array, you can change the list to an array.


2022-09-21 12:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.