返回true或false的问题

时间:2017-12-16 21:00:47

标签: java

基本上我想要的是,如果帐号是6个字符长,则返回true,如果长度不是6个字符,则返回false。我想我使用的是错误的方法或者其他东西,但是在过去的2个小时里,我一直在努力让它工作,因为我真的很喜欢java。

public class bankAccount
{
    private String accountNum;// instance variable

    public bankAccount () {
        accountNum = "X00000"; 
    }

    public String getaccountNum () {
        return accountNum;
    }

    public static void main(String []args) {
        bankAccount account = new bankAccount ();
        System.out.println(account.getaccountNum());
    }

    public boolean isValidLenght(String s) {
        if (s.length() == 6) {
            return true;
        }else {
        return false;
        }
    }
}

任何人都可以告诉我这里我做错了什么并指导我正确的方向吗? 非常感谢

2 个答案:

答案 0 :(得分:2)

  

我想要的是它打印出的帐号是X00000   声明是真还是假。敌人 - X00000真实

以下代码应该这样做

刚刚更改了print方法

中的main语句
public class bankAccount
{
    private String accountNum;// instance variable

        public bankAccount () {
            accountNum = "X00000"; 
        }
            public String getaccountNum () {
                return accountNum;
            }

    public static void main(String []args) {
        bankAccount account = new bankAccount ();
        System.out.println(account.getaccountNum() + " " + account.isValidLenght(account.getaccountNum()));
    }

    public boolean isValidLenght(String s) {
        if (s.length() == 6) {
            return true;
        }else {
        return false;
        }
    }
}

答案 1 :(得分:2)

您需要实际调用该方法:

public boolean isValidLength(String s) {
   return (s.length() == 6);
}

此外,您只需将isValidLength方法更改为并实现相同的效果:

webView.loadUrl("http://216.58.216.164/")
相关问题