Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Basic Math Expression Java Problem

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Basic Math Expression Java Problem

    import java.util.*;
    import java.text.*;
    import javax.swing.*;
    class Lab4Part2{
       public static void main (String[] args) {
    		String ex1;
    		Double num, F;
    		final int a=0, b=0;
    		JFrame myWindow=new JFrame();
    		myWindow.setSize(500,400);
    		myWindow.setTitle("Calculator");
    		myWindow.setVisible(true);
    		myWindow.setLocation(600,200);
    		ex1=JOptionPane.showInputDialog(myWindow, "Enter an expression");
    	   F=Double.parseDouble(ex1);
    		num=(a+B);
    		JOptionPane.showMessageDialog(myWindow, "The sum is "+num);
    	}
    }

    I need some help I keep getting an error when I try to run it on JGrasp. I have no clue what I'm doing wrong and for that matter I don't know what I have to do next if I am doing something wrong or not. However I'm trying to create a program where there are one input dialog that asking for the expression in "a+b" form like I would have to input "1+2" and then the second dialog would be a message giving the answer to that 1+2 which would show the message of 3. Thanks for helping.

    PS. I believe the Double.parseDouble is a wrong method in solving this issue and I believe I need to stack but I don't know how.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Basic Math Expression Java Problem

    I keep getting an error
    Please copy and paste here the full text of the error message.

  3. #3
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Basic Math Expression Java Problem

    What's up with the double thread post? Check back at your other thread, there are many responses.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Basic Math Expression Java Problem

    Please do not post the same question to the forums more than once. This thread is now locked. Your other thread:
    Basic Math Expression Java Problem

Similar Threads

  1. Math Problem
    By kidsforsale in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 14th, 2010, 04:09 PM
  2. Basic Java File I/O with Scanner Class Problem
    By miss confused in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 26th, 2010, 08:04 AM
  3. Magic square class (modular math problem)
    By mjpam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 30th, 2010, 10:56 AM
  4. Using Regular Expression (regex) in Java Programming
    By lordelf007 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 14th, 2010, 10:29 AM
  5. switch and math problem issues
    By emartino in forum Java Theory & Questions
    Replies: 1
    Last Post: January 19th, 2010, 05:34 PM