I have a compilation error using bluej java.

Here is the code:

while input.equals(!"q")

This is the error I get: '('

Could you please help me thanks :)

If i add to a semicolon to the end like this:

while input.equals(!"q");

I still get the same error.

The "not" operator is in the wrong location. You don't want to write "equals not q", you want to write "not equals q".

Try to figure out where to put the "!" based on that.

The "not" operator is in the wrong location. You don't want to write "equals not q", you want to write "not equals q".

Try to figure out where to put the "!" based on that.

Is it like this

"!q"

Nope. It doesn't go inside the parenthesis at all.

Nope. It doesn't go inside the parenthesis at all.

while input.equals!("q");

!
it mean not in Java language

!
it mean not in Java language

I know that thanks. I have fixed the error.Its like this:

while (!(input.equals("q")))

However,I have a new problem know:the loop keeps running I want it to stop and ask for more input and then loop..

Code:

import java.util.Scanner;

public class testing
{

// Code for the main method of the program
    public static void main(String[] args)
    {
        // Set up the scanner object. 
         Scanner in = new Scanner(System.in);

 // Ask user for input of phone number and store it in an appropriate variable
         
         System.out.print("Please type in input for the phone tx (to send a text) s (to start a call) e (end a call) c (perform a credit enquiry) tu (to up phone) q (to quit the application :");
         String input = in.next(); 
         //System.out.println("Your phone number is :" + phonenumber);
         
         while (!(input.equals("q")))
         
        {
        
            if (input.equals("s")){ 
                System.out.println("S has ben pressed");
              }
        
                else if (input.equals("tx")) 
        
        { 
            
           System.out.println(" tx has been pressed");
            
        }
        
            else if (input.equals("c")) { 
                
                System.out.println("c has been pressed");
            
               }
        
        else if (input.equals("e")) { System.out.println(" e has been pressed");
            
             }
        
        else if (input.equals("tu")) { System.out.println(" tu has been pressed");   
          
        in.next();
            
                }
        

  
        }
    }

}

why dont you use switch/case statements? for the default case, accept a new input. cos your programming style is very messy..
anyway, ur program keeps looping cos your in.next() is inside the else if loop. bring it outside..

why dont you use switch/case statements? for the default case, accept a new input. cos your programming style is very messy..
anyway, ur program keeps looping cos your in.next() is inside the else if loop. bring it outside..

Thanks ery much for the help and advice.I have realised that about the loop and hae ammended it accordingly. thanks xD

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.