-
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? :)
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);
}
}
-
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:
Code:
boolean n = charinp.isAlphabetic(a);
-
ah, thanksalot hardwired!! just getting used to the different return types : )