Results 1 to 3 of 3
  1. #1
    CyberFrog is offline Member
    Join Date
    Mar 2008
    Posts
    16
    Rep Power
    0

    Default Arguments in Main

    Hey all, just writing up this little bit of code and now am a bit confused? all i now want to do insert the argument acquired from the Keyboard.readchar() command into my method via the calling of an object i.e. new? My IDE says its found my return type boolean but a char is required, but I already have a return in my method? Here is my code anyway (it doesn't like the char n = ..........etc line). Hope someone ca help? :)


    Java Code:
    package Chapter4;
     
    import cs1.Keyboard;
     
    //Always start with Capitals - Java synatx
    public class IsAlpha {
        //Creates a new instance of IsAlpha
        ////This is also a constructor(no return type) and same name as the class.
        public IsAlpha(){
        }
         
        public boolean isalphabetic(char c){
        
            if (Character.isLetter(c)){
                return true;                          
                }
            else{
                return false;
                }
        }
       
            public static void main(String[]args){
            System.out.println("Please insert a character of your choice: ");
            char a = Keyboard.readChar();
            IsAlpha charinp = new IsAlpha();
            char n =  charinp.isalphabetic(a);
            System.out.println(n);
            
        }    
        }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    C:\jexp>javac isalpha.java
    isalpha.java:14: incompatible types
    found   : boolean
    required: char
            char n =  charinp.isAlphabetic(a);
                                          ^
    1 error
    The expression on the right side of the equals sign returns a boolean value. The declaration on the left is for a char. This is a type mismatch.
    Try:
    Java Code:
    boolean n =  charinp.isAlphabetic(a);

  3. #3
    CyberFrog is offline Member
    Join Date
    Mar 2008
    Posts
    16
    Rep Power
    0

    Default

    ah, thanksalot hardwired!! just getting used to the different return types : )

Similar Threads

  1. Finding arguments of Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 08:04 PM
  2. repetition of 'arguments'(?)
    By Igor in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 11:08 AM
  3. Variable No. of Arguments
    By Gajesh Tripathi in forum New To Java
    Replies: 2
    Last Post: 10-31-2007, 03:50 PM
  4. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  5. Replies: 1
    Last Post: 08-06-2007, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •