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

Thread: Help with three lines

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

    Default Help with three lines

    hi I'm having problems with this code:

    the line:
    if (yy % 400 == 0|| (yy% 100 !=0 && % yy% 4==0))
    -Says illegal start of expression
    else {System.out.println ("Input 3 digit Julian:");
    -says else without 'if'
    GtoJ (m,d,mod);
    JtoG (ddd,mod);
    -cannot find symbol

    What should i do? please help


    import java.util.Scanner;
    public class GtoJ {
    public static void main(String[] args) {
    int mm, dd,yy;
    int [] mod= {31,28,31,30,31,30,31,31,30,31,30,31};
    Scanner Sel= new Scanner (System.in);
    System.out.println (" Input Year:");
    yy= Sel.nextInt( );
    if (yy % 400 == 0|| (yy% 100 !=0 && % yy% 4==0))
    {mod [1]=29;}
    System.out.print("1 for GtoJ (),2 for J to G ()");
    int s= Sel.nextInt();
    if (s==1){
        int m = Sel.nextInt ();
        int d = Sel.nextInt ();
        System.out.println ("Input 2 digit number:");
            GtoJ (m,d,mod);
    else {System.out.println ("Input 3 digit Julian:");
           int ddd= Sel.nextInt ();
           JtoG (ddd,mod);
    }
    }
    }
    Last edited by Norm; February 13th, 2013 at 08:01 PM. Reason: Removed HTML tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,412
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default Re: Help with three lines

    Please post the full text of the error messages.
    The little bits and pieces you posted has left out important information.


    Please edit the code and properly format it. Nested statements should be indented.
    Too many statements state in the first column making the code hard to read and understand. The }s should not be in a column one beneath the other.

    Fixing the formatting will make it easier to see some of the errors.
    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: Help with three lines

    oh sorry i did it after i posted it:

    import java.util.Scanner;
    public class GtoJ {
    public static void main(String[] args) {
         int mm, dd,yy;
         int [] mod= {31,28,31,30,31,30,31,31,30,31,30,31};
    Scanner Sel= new Scanner (System.in);
         System.out.println (" Input Year:");
         yy= Sel.nextInt( );
    if (yy%400==0||(yy%100!=0&&%yy%4==0)) 
    {mod [1]=29;}
        System.out.print("1 for GtoJ (),2 for J to G ()");
        int s= Sel.nextInt();
        if (s==1)
    {
            int m = Sel.nextInt ();
            int d = Sel.nextInt ();
            System.out.println ("Input 2 digit number:");
                GtoJ (m,d,mod);
    else {System.out.println ("Input 3 digit Julian:");
            int ddd= Sel.nextInt ();
            JtoG (ddd,mod);
            }
        }
    }



    For the errors i got this:For the line:

    if (yy%400==0||(yy%100!=0&&%yy%4==0))
    illegal start of expression

    else {System.out.println ("Input 3 digit Julian:");

    -else without 'if'

    JtoG (ddd,mod); & GtoJ (m,d,mod);
    -Cannot find symbol
    symbol method: GtoJ (int, int,int [])
    location class GtoJ
    Surrounded with
    ...introduce


    Those are the errors within the program and once i run it:

    run:
    Input Year:
    1992
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at gtoj.GtoJ.main(GtoJ.java:13)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,412
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default Re: Help with three lines

    The formatting is still poor. It is hard to read code when the {s are all over the place.

    Also the error messages are a mess and hard to read. They don't include the line number where the error happens.

    Here is a sample of an error message from the javac command:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    What symbol is not found in the error message you posted?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help with three lines

    oh, i dont know if this is better i added a screen shot

    I fixed the error in the 'If' statement its only lines 22,23,25 that i dont understand im not sure what to put infront of the GtoJ and JtoG


    78678.jpg



    These are the errors with those lines:
    1.jpg2.jpg3.jpg

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,412
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default Re: Help with three lines

    Sorry, I can't read those images. Can you copy and paste the text of the error messages. See post#4 for a sample of what the output from the javac compiler gives.

    The poor formatting is hiding problems in the code.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help with three lines

    oh i dont think it does that im netbeans, i have a mac

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,412
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default Re: Help with three lines

    The poor formatting is hiding problems in the code.

    Sorry, I don't know how to execute the java compiler on a mac.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: Help with three lines

    GG

  10. #10
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Help with three lines

    I don't use Macs, so I cant help you there. As for your code, it's difficult to read because you have { and } placed very awkwardly. Keep in mind, with NetBeans, it will show you which braces open and close each other based on how you wrote it and if there are too many, however, it does not check whether there are logical errors resulting from misuse of braces. From one of your screenshots, on lines 22 and 25 have several errors. First, you're trying to pass variables into a class instead of into a method. Second, you're trying to pass an integer array as an integer. Third, the methods GtoJ and JtoG do not exist anywhere in the code you provided, which is why the compiler is giving you those errors for it.

    Although it's not an error, on line 8, you never do anything with 2 of the 3 int variables. What is their purpose in your code? If they have none, delete them. Also, what are you trying to use the array for because you only have one of its elements replaced by 29?

    Adjust the formatting and it's possible you'll find more errors. A chunk of your code needs to be re-written, so fix the other errors that are easier to handle first.

Similar Threads

  1. [SOLVED] 2 Lines Stuffs.
    By Saintroi in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 11th, 2012, 08:22 AM
  2. Perpendicular Lines
    By captain in forum Object Oriented Programming
    Replies: 1
    Last Post: March 5th, 2012, 07:46 PM
  3. Reversing lines using LinkedList
    By velop in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 14th, 2011, 05:10 AM
  4. Problem with Output # of lines
    By coyboss in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 09:21 PM
  5. How would you get a JTextArea to know how many lines it had?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 20th, 2011, 06:58 PM