Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need help with this code?

    package HelloApp;

    import java.util.Scanner;



    public class Main {


    static Scanner sc = new Scanner (System.in);

    public static void main(String[] args) {
    {

    JOptionPane.showMessageDialog(null, "Enter an integer:");
    int x= sc.nextInt();
    JOptionPane.showMessageDialog(null, "You entered" + x + ".");
    }
    Keeps saying I'm missing a bracket, i correct it but the problem persists.

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    25
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Keeps saying I'm missing a bracket
    Here is 3 opening curly brackets and only 1 closing. You really think it is normal?

  • #3
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OK, besides that...

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by dannyboi View Post
    OK, besides that...
    I don't understand this followup question. That is literally all that is wrong with it. Make sure you add the missing closing braces. Just the class and the method itself; I'd remove the redundant open and close braces as well though.

    Now other than this, you are mixing swing and command line components. This is bizarre to say the least, if you want to use a gui, then keep it all in the gui. Use the showInputDialog instead and try/catch an Integer.parseInt call. Otherwise, even packed as a jar you'd need to execute it on the command line every time in order to receive input.

  • #5
    New Coder
    Join Date
    Feb 2012
    Location
    uk
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just follow the rule that for every open bracket, you need a closed bracket. Code needs to balance


  •  

    Tags for this Thread

    Posting Permissions

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