Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:22:49+00:00 2026-05-23T12:22:49+00:00

I am totally new to programming. I´m reading some tutorials on the internet, and

  • 0

I am totally new to programming. I´m reading some tutorials on the internet, and also Barry Burds “Java for dummies” while trying to learn programming Java. I have tried all variations I could think of without success.
In one exercise I am supposed to make the following program to print a message in a “messageDialogBox” which should contain the numbers wrote in by the user of the program. Unfortunately I get thhe following error message when trying to compile: Can somebody please help me get the code to work? What is wrong with the code?

5 errors
Addition2.java:24: ')' expected
      JOptionPane.showMessageDialog( null, firstnumber "+" secondnumber
                                                      ^
Addition2.java:25: not a statement
      + sum, "Results", JOptionPane.PLAIN_MESSAGE );
      ^
Addition2.java:25: ';' expected
      + sum, "Results", JOptionPane.PLAIN_MESSAGE );
           ^
Addition2.java:25: not a statement
      + sum, "Results", JOptionPane.PLAIN_MESSAGE );
                                   ^
Addition2.java:25: ';' expected
      + sum, "Results", JOptionPane.PLAIN_MESSAGE );

The code is the following:

import javax.swing.JOptionPane;

public class Addition2
{
   public static void main( String args[] )
   {
      String firstnumberstring;
      String secondnumberstring;

      int firstnumber;
      int secondnumber;
      int sum;

      firstnumberstring = JOptionPane.showInputDialog( 
            "Write first number" );
      secondnumberstring =
         JOptionPane.showInputDialog( "Write second number" );

      firstnumber = Integer.parseInt( firstnumberstring );
      secondnumber = Integer.parseInt( secondnumberstring );

      sum = firstnumber + secondnumber;

      JOptionPane.showMessageDialog( null, firstnumber "+" secondnumber
      + sum, "Results", JOptionPane.PLAIN_MESSAGE );
   } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:22:49+00:00Added an answer on May 23, 2026 at 12:22 pm

    You need to concatenate strings using the string cat operator: +

    JOptionPane.showMessageDialog( null, firstnumber  + "+" + secondnumber + " = " + sum, "Results", JOptionPane.PLAIN_MESSAGE );
    

    Btw; it’s considered a good thing to declare variables where they are assigned for the first time – and not sticking to the old c- requirement (with ancient roots) that all variables must be declared before the actual code.

    String firstnumberstring = JOptionPane.showInputDialog( 
            "Write first number" );
    

    It helps a little when trying to figure out where a variable is used.
    It’s particulary good when a variable is used only in a specific scope; ( inside curly brackets)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m totally new to programming in java, and following some basic tutorials for my
First and foremost. I'm totally new to programming in Excel. I'm trying to make
I am totally new to programming and to some new technologies. Right now I
I am totally new to math/numerical analysis programming and I was looking all over
I'm totally new to both java and java Server worlds... But I've a good
I am totally new to emacs and is starting to learn how to use
I'm totally new to GreaseMonkey, but I'm trying to make a little script. //
I'm using Delphi 7, totally new to database programming, and need ODBC. I am
I'm totally new to Ruby but not to programming. All I did was going
I'm totally new to powershell, and I need some help to get started. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.