Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Entering a non-numeric character into an if statement...

807588Jan 20 2009 — edited Jan 21 2009
Hi guys,

I've created an if statement which produces these outputs....

if you enter 0, you get an output of +"zero"+.
if you enter any number over 0, you get an output of +"numeric"+.
if you enter a non-numeric character, you get an output of +"non-numeric"+.

It works when i enter in numeric characters, but when i enter in a non-numeric character, like h, i get a "Error: cannot find symbol - variabal h" on the object. I've written it in brackets and it still won't work.

Can anyone give me hint where i'm going wrong?

Here's my code...
public class Numbers
{
    private char c;
    
    /**
     * Constructor for objects of class Numbers
     */
    public Numbers()
    {
        // initialise instance variables
        char c = 1;
    }

    /**
     * Enter value...
     */
    public void getValue(char c)
    {
        if(c < 1) {
            System.out.println("Zero");
        }
        else if (c >= 1) {
            System.out.println("Number");
        }
        else {
            System.out.println("Non-numeric");
        }
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2009
Added on Jan 20 2009
28 comments
1,079 views