Reputation: 550
I'm trying to do a pyramid like:
a
bc
def
ghij
klmno
but it gives me the error: Char cannot be dereferenced
I have a very easy code:
public class PiramideLetras {
public static void main (String args[]) {
char cha = 'A';
for (int i=0;i<5;i++){
for(int y=i;y>=0;y--){
System.out.print(cha);
int b = cha.getNumericValue();
}
System.out.println("");}
}
}
Why I get this error?
Upvotes: 0
Views: 805
Reputation: 1500485
Char.getNumericValue
is a static method which takes the value as an argument. So you want:
int b = Char.getNumericValue(cha);
You can't use primitive types as the target of any kind of method call.
Upvotes: 8