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 4 of 4

Thread: Problem with code.

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Problem with code.

    Hi i have a problem with this code and im not sure what i need to add to fix it:

    HTML Code:
    package gtoj;
    public class GtoJ {
        public static void main(String[] args){
            int YY;
            int DD;
            int MOD []= {31,28,31,30,31,30,31,31,30,31,30,31};
    if (YY%400 == 0 || (YY% |DD|=0DD YY %4==0)) MOD [i]=29;
        }
    }

    With the line that starts int MOD: it states "this array is only written to, never read from"
    the next line with the "if" says
    "varible YY may not have been intialized
    illegal start of expression
    variable DD miht not have been intialized
    ')' expected
    variable decleration not allowed here
    ';' expected
    cannot find symbol
    variable i
    location: classGtoJ"


    Im not sure what it means, im not sure if i needed to declare the int YY and DD, also where do i input the dates that would be converted, also I'm not sure if i wrote the if statement correctly with the "|" and "!"

    --- Update ---

    also should i change the public static void.. to public static int?

    would that work, each time i try it, the program tells me to add the static void

    and Thanks in advanced for helping


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Problem with code.

    Most of the errors are explained in the error message.
    The compiler wants all variables defined in a method to be given a value before they are used.
    The "cannot find symbol" error means that the compiler can not find a definition for the variable mentioned in the error message.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Problem with code.

    yes i know but im unsure for what i have to do for the if statement

    do i insert the numbers for DD and YY, i feel that the way i wrote the if statement must have a error

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Problem with code.

    what i have to do for the if statement
    Which error are you talking about?

    To make the condition in the if statement clearer and easier to read and understand, put ()s around each boolean expression. A boolean expression has these three things: leftOperand booleanOperator rightOperand
    For example:
    if((a > b) && (c < d))

    a, c and (a > b) are leftOperands
    > && and < are booleanOperators
    b, d and (c > d) are rightOperands
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  2. I have a problem with my code I think
    By byrne in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 12th, 2011, 05:18 AM
  3. problem in my code
    By dhruvguys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 06:18 AM
  4. What is the Problem With This Code?
    By olufemi1712 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 18th, 2011, 10:05 AM
  5. Problem with the code
    By noFear in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 9th, 2010, 11:28 AM