Hi all,

I'm just starting java and had to create a method to return the amount of text messages needed for a message x characters long. I'm having trouble compiling and not sure exactly why

public void msgsReqd(int msgLength)
    {
        int numMsgs, smsLength = 160;
        msgLength  / smsLength = numMsgs;
        if (msgLength % 160 >= 1)
        {
            numMsgs = numMsgs + 1;
        }
        if (numMsgs == 1)
        {
            System.out.println("You will need " + numMsgs + " text");
        }
        else
        {
            System.out.println("You will need " + numMsgs + " texts");
        }

I am getting an unexpected type error at the line msgLength / smsLength = numMsgs. I have tried changing to msgLength / 160 with the same error. I know its probably something idiotic but I've been staring at it for 20 mins now so any help would be appreciated.

PS this method is part of a larger class in which I have a number of other practice methods which are all working fine and using BlueJ so not a bracket issue.

line 4 looks the wrong way round - java syntax is
variable = formula; You have formula = variable;

msgLength  / smsLength = numMsgs;

This isn't allowed as you probably can't (and definitely don't want to) assign a value to the quotient of 2 numbers. do you want

numMsgs = msgLength  / smsLength;

?

your assignment is in reverse This is what u want to do

numMsgs = msgLength  / smsLength

Thanks guys I feel like an idiot for not spotting that :)

Its all good. we all made silly mistakes like this when we started out; that how u learn and get better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.