Results 1 to 6 of 6
  1. #1
    aaden1 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default java code help please beginner

    i don't know where iv gone wrong i basically want to type in "M" in the showinputdialogbox and the messagedialogbox to show Monday but for the whole week . Code is below and error below that thanks.




    String input = JOptionPane.showInputDialog("Enter the days of the week in the following abbreviations: M,Tu,W,Th,F,Sa,Su");

    If(input.equals(M));
    {
    JOptionPane.showMessageDialog(null, "Monday");
    } if else(dayinput.equals("Tu"))
    {
    JOptionPane.showMessageDialog(null, "Tuesday");
    } else if(dayinput.equals("W"))
    {
    JOptionPane.showMessageDialog(null, "Wednesday");
    } else if(dayinput.equals("Th"))
    {
    JOptionPane.showMessageDialog(null, "Thursday");
    } else if(dayinput.equals("F"))
    {
    JOptionPane.showMessageDialog(null, "Friday");
    } else if(dayinput.equals("Sa"))
    {
    JOptionPane.showMessageDialog(null, "Saturday");
    } else if(dayinput.equals("Su"))
    {
    JOptionPane.showMessageDialog(null, "Sunday");
    } else {
    JOptionPane.showMessageDialog(null, "Error you did not enter days of the week with the abbreviations set");
    }
    }
    }

    error: '(' expected
    } if else(dayinput.equals("Tu"))
    ^
    error: illegal start of expression
    } if else(dayinput.equals("Tu"))
    ^
    error: ')' expected
    } if else(dayinput.equals("Tu"))
    ^
    error: ';' expected
    } if else(dayinput.equals("Tu"))
    ^
    error: 'else' without 'if'
    } else if(dayinput.equals("W"))
    ^
    5 errors

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: java code help please beginner

    Please use [code] tags [/code] when posting code.
    Many people won't read unformatted code.

    Also it helps if you post your actual code...the 'if' keyword is not 'If' and, since there's no compilation error pointing that out, this is not the code you compiled.

    I'm guessing the problem is the semi colon at the end of:
    Java Code:
    if(input.equals(M)); <-- right here.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: java code help please beginner

    Wow...many errors :D

    If(input.equals(M)); --> three of them in this line. If -> if, equals(M) -> equals("M") and delete the ";" at the end
    then read a tutorial/book about if-else or compare your code with The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    And what is "dayinput"?
    :D

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: java code help please beginner

    Also:
    Java Code:
    if else(dayinput.equals("Tu"))
    That one needs to be "else if"

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default Re: java code help please beginner

    aaden1, please go through the Forum Rules -- particularly the third paragraph.

    Please also go through Guide For New Members and BB Code List - Java Programming Forum and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: java code help please beginner

    And don't PM people for answers...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 8
    Last Post: 06-06-2011, 02:27 AM
  2. Assist a Beginner's Breakout Code
    By jjs in forum New To Java
    Replies: 1
    Last Post: 03-23-2011, 01:15 AM
  3. Replies: 8
    Last Post: 11-05-2010, 01:52 PM
  4. Replies: 1
    Last Post: 10-24-2009, 02:13 AM
  5. Replies: 3
    Last Post: 12-10-2008, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •