Skip to Main Content

New to Java

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!

non-static method isEven(int) cannot be referenced from a static context

843785Jan 29 2009 — edited Jan 29 2009
That is the error message that I am getting. I am not sure what to do to get it run. Is there a way to make method isEven(int) static so that it can be referenced???? Thanks to all in advance!


import java.util.Scanner;

/**
*
* @author Jason
*/
public class evenOdd
{

public static void main (String[] args)
{
Scanner input = new Scanner (System.in);
{
while (input.hasNext())
{
int number = input.nextInt();

if ( isEven( number ) ) *<----------------------------------------------------- Here is the problem*
System.out.printf( "%d is even\n", number );
else
System.out.printf( "%d is odd\n", number );
}
}
}


public boolean isEven( int number )
{
return number % 2 == 0;
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 26 2009
Added on Jan 29 2009
6 comments
283 views