Results 1 to 7 of 7
Like Tree2Likes
  • 1 Post By Fubarable
  • 1 Post By pbrockway2

Thread: Simple if code not working? Assistanc wanted.

  1. #1
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Simple if code not working? Assistanc wanted.

    Why is this code not working?
    import java.util.Scanner;

    public class DiningDollars {

    private static Scanner keyboard = new Scanner (System.in);
    private static final double SUB_COST = 5;
    public static void main (String[] args);

    System.out.println("How many dining dollars do you have? ");
    double currentDollars = keyboard.nextDouble();

    if (currentDollars < (SUB_COST * 3)) {
    System.out.println("Take two friends to subway!");
    currentDollars -= (SUB_COST*3);
    }
    System.out.println("You are now left with " + currentDollars);
    }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Simple if code not working? Assistanc wanted.

    "not working" might need a little elaboration: Does this code compile? If not and you can't understand the compiler's messages, post them and indicate the lines of your code to which they refer.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Simple if code not working? Assistanc wanted.

    Quote Originally Posted by dunboody View Post
    Why is this code not working?

    Java Code:
    import java.util.Scanner;
    
    public class DiningDollars {
    
      private static Scanner keyboard = new Scanner (System.in);
      private static final double SUB_COST = 5;
      public static void main (String[] args);
    
        System.out.println("How many dining dollars do you have? ");
        double currentDollars = keyboard.nextDouble();
        
        if (currentDollars < (SUB_COST * 3)) {
          System.out.println("Take two friends to subway!");
          currentDollars -= (SUB_COST*3);
        }
        System.out.println("You are now left with " + currentDollars);
      }
    }
    Can you tell us how it's not working?

  4. #4
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: Simple if code not working? Assistanc wanted.

    I'm getting errors on lines 9, 12, and 16. It's saying things like <identifier> expected, and illegal start of type, and ';' expected.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Simple if code not working? Assistanc wanted.

    Quote Originally Posted by dunboody View Post
    I'm getting errors on lines 9, 12, and 16. It's saying things like <identifier> expected, and illegal start of type, and ';' expected.
    Look just above the line causing the error. Your problem is you've got a misplaced semicolon on the line where you declare your main method.
    pbrockway2 likes this.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Simple if code not working? Assistanc wanted.

    Sometimes the compiler will get *very* confused by a relatively simple mistake and spit out all sorts of messages for the subsequent code. The first thing to do in such cases is to look just above where the messages start.
    Fubarable likes this.

  7. #7
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: Simple if code not working? Assistanc wanted.

    Yeah, it's the semicolon on the main method line. Thanks, y'all!

Similar Threads

  1. Simple TCP Client/Server not working?!?!?!
    By FiniteRed in forum Networking
    Replies: 1
    Last Post: 07-15-2011, 03:23 PM
  2. Replies: 0
    Last Post: 05-24-2011, 07:50 AM
  3. Simple code not working
    By davetheant in forum New To Java
    Replies: 7
    Last Post: 02-04-2011, 12:51 AM
  4. Simple TCP chat application not working for me
    By sundarrajan in forum New To Java
    Replies: 0
    Last Post: 08-13-2009, 08:31 AM
  5. simple validations not working
    By rahaman.athiq in forum Web Frameworks
    Replies: 0
    Last Post: 11-06-2008, 06:10 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
  •