dimanche 31 octobre 2021

Java - assign number of character less than 4

/* * mutator method * parameter changedNumber * method checks the number of characters in the parameter * if the number of characters is less than 4 assign * listingNumber a string of 4 zeros, otherwise assign * listingNumber the value of the parameteer */

My if statement returns the error code 'bad operand types for binary operator <' I am not too sure how to set the number of character less than 4

public void setListingNumber(String changedNumber)
{
    listingNumber = changedNumber;
    
        if (changedNumber < 4) {
       
            listingNumber = "0000";
        }
        else {
            listingNumber = changedNumber;
    }
}

Aucun commentaire:

Enregistrer un commentaire