Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java Beginner. Help needed.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    My Mood
    Amazed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile 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.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    3,440
    My Mood
    Mellow
    Thanks
    86
    Thanked 475 Times in 466 Posts

    Default 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.

  3. #3
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    150
    My Mood
    Cheerful
    Thanks
    11
    Thanked 25 Times in 25 Posts

    Default 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.

Similar Threads

  1. Java Programming for beginner HELP needed ...
    By Vinayaka Sp in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2013, 09:26 AM
  2. Grails Developer Needed - URGENTLY NEEDED *WORK FROM HOME*
    By IngeniumR in forum Paid Java Projects
    Replies: 0
    Last Post: February 5th, 2013, 06:19 AM
  3. Very beginner level code help needed.
    By dcalabro in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2013, 05:26 PM
  4. Help needed for beginner. Im so confused
    By walrus212 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 14th, 2011, 12:47 PM
  5. beginner-urgent java help needed
    By joeyyusiyi22 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2011, 10:43 AM