Results 1 to 3 of 3
Thread: Arguments in Main
- 03-30-2008, 04:58 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 16
- Rep Power
- 0
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); } }
- 03-30-2008, 08:31 PM #2
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.Java Code:C:\jexp>javac isalpha.java isalpha.java:14: incompatible types found : boolean required: char char n = charinp.isAlphabetic(a); ^ 1 error
Try:
Java Code:boolean n = charinp.isAlphabetic(a);
- 03-30-2008, 09:37 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Finding arguments of Servlet
By Java Tip in forum Java TipReplies: 0Last Post: 01-25-2008, 07:04 PM -
repetition of 'arguments'(?)
By Igor in forum New To JavaReplies: 3Last Post: 12-13-2007, 10:08 AM -
Variable No. of Arguments
By Gajesh Tripathi in forum New To JavaReplies: 2Last Post: 10-31-2007, 02:50 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
exception in thred main java.lang.nosuchmethoderror: main
By fernando in forum Java AppletsReplies: 1Last Post: 08-06-2007, 09:11 AM


LinkBack URL
About LinkBacks

Bookmarks