Results 1 to 4 of 4
  1. #1
    hello111 is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default "else" without "if" error .. help

    NVM figure out the problem on my own!! Thanks anyway, so happy :) please closed
    Last edited by hello111; 02-14-2013 at 11:27 PM.

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

    Default Re: "else" without "if" error .. help

    Please edit your post above and add code tags:

    Please the tag [code] above your posted code block and the tag [code] below your code block like so:

    [code]
    Java Code:
    // your code goes here
    public class Foo {
    
    }
    [/code]

    This way we'll be better able to see your code formatting which should show us if the offending else has a matching if on the right level just before it.

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

    Default Re: "else" without "if" error .. help

    Here's the removed content:

    everything works except at the "else if" statement. I get an error:
    Bankaccount.java:34: error: 'else' without 'if'
    else if (button.equals("withDrawal"))
    ^
    1 error


    import javax.swing.JOptionPane;

    public class Bankaccount {
    public static void main(String [] args)
    {
    int balance;
    int newBalance;
    int deposit = 0;
    int withDrawal = 0;
    int transferMoney;
    String button;

    balance = Integer.parseInt(JOptionPane.showInputDialog("Ente r Bank Account Balance"));


    if (balance < 0)
    {
    JOptionPane.showMessageDialog(null, "You must contact bank's customer service department");
    }
    else
    {
    button = JOptionPane.showInputDialog("Enter button: Create Deposit, Make Withdrawal, or Transfer Money");

    if (button.equals("deposit"))
    {
    deposit = Integer.parseInt(JOptionPane.showInputDialog(null, "Deposit Amount"));
    }
    newBalance = balance + deposit;
    {
    JOptionPane.showMessageDialog(null, "New Balance" +" "+ newBalance);

    }
    }
    else if (button.equals("withDrawal"))
    {
    withDrawal = Double.parseDouble(JOptionPane.showInputDialog(nul l, "Withrawal Amount"));

    }

    }
    }

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

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

    Default Re: "else" without "if" error .. help

    Next time, rather than delete your question, please post your solution here so that you can help folks with similar problems in the future.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 06:26 PM
  2. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 05:38 PM

Posting Permissions

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