# Java Beginner. Help needed.

• September 30th, 2013, 12:18 PM
Jack1
Java Beginner. Help needed.
Determine if a String is even or odd. An even number has a remainder of zero when being divided by two. An odd number is any number that does not have a remainder of zero when being divided by two.

I would really appreciate if someone can help me with this Lab05c

import static java.lang.System.*;
import java.util.Scanner;

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

}
}

----------------------------------------------------------------------------------------------------

import static java.lang.System.*;
import java.util.Scanner;

public class StringOddOrEven
{
private String word;

public StringOddOrEven()
{

}

public StringOddOrEven(String s)
{

word = s;
}

public void setString(String s)
{
word = s;

}

public boolean isEven()
{

return false;
}

public String toString()
{
String output="";

return output;
}
}

Sample Data :
cat
boot
it
a
eleven
thirteen
odd
even

Sample Output :
Enter a word :: cat
cat is odd.

Enter a word :: boot
boot is even.

Enter a word :: it
it is even.

Enter a word :: a
a is odd.

Enter a word :: eleven
eleven is even.

Enter a word :: thirteen
thirteen is even.

Enter a word :: odd
odd is odd.

Enter a word :: even
even is even.
• September 30th, 2013, 01:16 PM
GregBrannon
Re: Java Beginner. Help needed.
Please read the Announcement topic at the top of most sub-Forums to learn how to post correctly and ask questions that get attention and useful answers.
• October 3rd, 2013, 12:18 AM
GoodbyeWorld
Re: Java Beginner. Help needed.
Yes, I think I can understand what you're getting at.

I think you want the

length() method of the String class as you're trying to figure if the string length is even or odd, am I right?

Also, you should consider using the modulus ( % ) operator. It is like the division (/) except that it returns the int remainder of the division.

For instance 5%2 = 1

I think you can do it now.