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 8 of 8

Thread: simple calculation code

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default simple calculation code

    am trying to make this code work to do simple calculation
     
    package inputuserifstatement;
    import javax.swing.JOptionPane;
    public class Inputboxesifstatement {
     
        public static void main(String[] args) {
    double firstnumber;
            firstnumber = JOptionPane.showInputDialog("Enter Number");
     
           double secondnumber;
            secondnumber = JOptionPane.showInputDialog ("Enter Second Number");
     
    double answer;
            answer = firstnumber + secondnumber;
     
          JOptionPane.showMessageDialog(null, answer);
          System.exit(0);


  2. #2
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: simple calculation code

    You have an illegal whitespace and you can't just convert at string to double like you try to
    Ruby 'cause I can - Java 'cause I want - C# 'cause I have to

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: simple calculation code

    ok so what should i do
    am a still a learner, just started 3 days ago

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: simple calculation code

    You need to convert the String into a double value. This is easily accomplished using the following method: parseDouble();
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  5. The Following User Says Thank You to newbie For This Useful Post:

    dokunbam (October 7th, 2013)

  6. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: simple calculation code

    some thing is wrong here too
    i will not give up
    i hope some day i will give answer to people's problem


        public static void main(String[] args) {
            // TODO code application logic here
     
    int user = 18;
            if(user < 16)
            { System.out.println("user is underage");
            }
            else if (user >= 18 && < 50) 
            {
         System.out.println("Required Age");
            }  
    else {System.out.println("not of required age");

  7. #6
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: simple calculation code

    else if (user >= 18 && < 50) should be else if (user >= 18 && user < 50). This is a typical rookie mistake, as it does make sense. However, each side of the || and && operators need to evaluate to either true or false independently.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  8. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: simple calculation code

    Guys help me out on this too

     public static void main(String[] args) {
            // TODO code application logic here
            int[][]aryNums;
            aryNums = new int [2][6];
            aryNums[0][0] = 10;  aryNums[1][0] = 60;
            aryNums[0][1] = 20;  aryNums[1][1] = 50;
            aryNums[0][2] = 30;  aryNums[1][2] = 40;
            aryNums[0][3] = 40;  aryNums[1][3] = 30;
            aryNums[0][4] = 50;  aryNums[1][4] = 20;
            aryNums[0][5] = 60;  aryNums[1][5] = 10;
     
            {
           System.out.println(aryNums[][] + " ");
            }
                   System.out.println(" ");

  9. #8
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: simple calculation code

    I have already replied to the thread you posted the exact question on

    Pls me out on this arrays number print

    don't post new questions on a different questions thread and don't double post please. makes it harder for us to help you.

Similar Threads

  1. Need help with simple code
    By DreC32 in forum Object Oriented Programming
    Replies: 7
    Last Post: August 6th, 2013, 01:55 PM
  2. Looking for a simple code
    By Pipar in forum Java Theory & Questions
    Replies: 7
    Last Post: July 22nd, 2013, 01:12 PM
  3. [SOLVED] Can anyone explain this code to me? Calculation of mean and variance.
    By hemla in forum Object Oriented Programming
    Replies: 5
    Last Post: March 24th, 2013, 04:17 PM
  4. loan calculation applet code
    By haxn in forum AWT / Java Swing
    Replies: 1
    Last Post: September 1st, 2012, 12:38 AM
  5. Need help with simple code
    By suxen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 21st, 2011, 07:10 PM