Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to check if a number is even or odd which returns a string. I wrote the code but when i run, after i enter the number nothing happens.
import java.util.Scanner;

public class Demo {
	public static void main(String[] args) {

		Scanner in = new Scanner(;

		System.out.print("Enter a number: ");
		int number = in.nextInt();


	public static String evenOdd(int n) {
		String s = "";

		if (n % 2 == 0) {
			s = n + " is an even number";
		} else {
			s = n + " is an odd number";

		return s;



What I have tried:

Writing the method body, and after calling the method in my main, nothing happens after i enter the number.
Updated 26-Nov-19 2:41am

1 solution

Nothing happens, because you do not print the output of evenOdd to the console.

instead of only evenOdd(number) should work. Or you can make sure that it prints in evenOdd instead of returning the output, that's also an option.
Share this answer
ridoy 5-May-16 14:33pm    
a 5.
Thomas Daniels 5-May-16 14:57pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900