Not sure what i've done wrong

The problem is to allow a user to input 2 numbers... then allow the user to choose the mathematical operation performed. Ive used if statements but it seems after you chose what operation you want to use it skips the if statements and goes straight to the answer... which is always 0. any help is appreciated.
import javax.swing.JOptionPane;
public class Calculate1
public static void main(String args[])
     int number1=0, number2=0, answer=0, choice1;
     String num1, num2, choice;     
     //Input Dialog boxes
num1=JOptionPane.showInputDialog(null,
     "Enter the first number: ", "First number",
     JOptionPane.QUESTION_MESSAGE);
     num2=JOptionPane.showInputDialog(null,
     "Enter the second number: ", "Second number",
     JOptionPane.QUESTION_MESSAGE);
     //Convert values from string to int
     number1=Integer.parseInt(num1);
     number2=Integer.parseInt(num2);
     //Math operation input box
     choice=JOptionPane.showInputDialog
          ("To add your numbers, press A" +
          " \nTo subtract your numbers, press S" +
          " \nTo multiple your numbers, press M");
     if (choice == "a")
     answer = number1 + number2;
     else if (choice == "s")
     answer = number1 - number2;
     else if (choice == "m")
     answer = number1 * number2;
     // Answer statement to screen
JOptionPane.showMessageDialog(null,
     "Your answer is " + answer, "Your answer",
          JOptionPane.INFORMATION_MESSAGE);
System.exit (0);

to illustrate aegons' reply, see this code
public class TestStrings {
public static void main(String[] args) {
  String test = args.length == 0 ? "TEST" : args[0];
  System.out.println("TEST".equals(test));
  System.out.println("TEST" == test);
}this code here i haven't compiled nor run.
but i assume that if you start it the way java TestStrings TEST, then it prints out:
true
false
but if you run it without first parameter "TEST", then it might even print out:
true
true
since internaly that "TEST" and variable test have pointers to the same memory region.
but now if you run it with first parameter other than "TRUE", then it prints out:
false
false
(which shouldn't surprise you)
now there was a place where equation check with == could return true, that might seem convenient way for checking strings, but really it's not, because it works as we might excpect it, only with some JRE implementations and only in test programs that are quite small and hardcoded...
i'm telling that because i don't want others to go wander off from their dayjob only because some sample programms make it look like they had implemented some fancy == handling in newer JRE/SDK
(maybe it was interesting....)

Similar Messages

  • HT1688 Hi, just bought my daughter an Iphone 4s and I can't get it to let her on youtube, Facebook etc., keeps saying no internet connection. My husband and I have 3G smartphones and we can get on them on ours, so I'm not sure what I'm doing wrong. Also,

    Hi, just bought my daughter an Iphone 4s and I can't get it to let her on youtube, Facebook etc., keeps saying no internet connection. My husband and I have 3G smartphones and we can get on them on ours, so I'm not sure what I'm doing wrong. Also, my other daughter has the same phone and has no trouble getting on these sites either. Any information to help is greatly appreciated. Thanks

    Well, did you activate this new phone?

  • I am in Aperture photos-browser - view. Amtrying to find "sort"  by file name to elimanate duplcates.  Sort option does not appear. Not sure what I am doing wrong.

    I am in Aperture -photos - browser - view.  Am trying to find "Sort"  by filename to elimate duplicates. I cannot find "sort in Viewer and not sure what I am doing wrong.  Help

    This is what the top of the Viewer should look like:
    Here is the same view with the pulldown opened:
    What is it that you see? Include a screenshot.

  • Hi.  I am having issues with copying files to my shared WB 2TB HDD connected to my airport extreme.  Comes up with error 50.  I am using a Macbook Pro to copy from so not sure what I am doing wrong.  Can someone help? thanks Rory

    Hi.  I am having issues with copying files to my shared WB 2TB HDD connected to my airport extreme.  Comes up with error 50.  I am using a Macbook Pro to copy from so not sure what I am doing wrong.  Can someone help? thanks Rory

    These links might provide some information that may be of help.
    http://support.apple.com/kb/TA20831
    https://discussions.apple.com/message/2035035?messageID=2035035
    I've encountered this error myself upon occasion.  If I remember correctly, it was a permissions/ownership issue with the some of the files I was copying.

  • I am trying to print redplum coupons and I can't, help.  I have updated java, adobe flash, and made sure my printer was set on default.  I am not sure what I am doing wrong.  I have contacted redplum and no one will help.

    I am trying to print redplum coupons and I can't, help.  I have updated java, adobe flash, and made sure my printer was set on default.  I am not sure what I am doing wrong.  I have contacted redplum and no one will help.

    No Apple response???  Redplum/Valassis will not help either.  I searched, using the cups error message and though it is Unbuntu, same error so maybe useful...only problem: details would not display unless I join Unbuntu forum.  What a pain to do anything with my Mac or find any help.  I honestly regret buying this buggy OS.
    Anyway, here is what I found, FYI:
    http://ubuntuforums.org/showthread.php?t=483415
    As the old saying goes: when in doubt, consult the manual. The problem appears to be that I added the printer using the KDE Add Printer Wizard. It was automatically given a "socket" URI instead of an "lpd" one. When I:
    - altered the printer settings at http://localhost:631 (the CUPS admin page) as instructed in the manual for the printer, and
    - copied the PPD file into a second place on the hard drive (as instructed on ubunutuforums, see the link above)
    ..everything started working.
    It's still slower than windows, but I can live with that
    Probably a simple fix. Change the socket I.P. to match the printer I.P. like this:
    socket://192.168.1.86:9100. The thing I'm concerned with using socket:// is that AFAIK the printer I.P. must not change. In my case I'm able to assign a static I.P. address to the printer but it's something to consider.
    I found that the only thing I needed to do was change socket to lpd (and remove :9100 off the end as well). See Solving Ubuntu printer “broken pipe” problem (DocuPrint C525A) . BTW thanks for steering me in the right direction - very grateful.      
    Solving Ubuntu printer “broken pipe” problem (DocuPrint C525A)
    Posted on November 25, 2008
    Are you having a problem with your printer under the latest versions of Ubuntu (perhaps it worked under an older version)? Are you able to print short documents, but not longer, or more graphics-intensive, documents? (e.g. the unfortunate people at http://ubuntuforums.org/showthread.php?t=625493). Do they sit there as Processing for ages and then switch to Held? If you have the same problem I had the solution I tried may work for you too. Firstly, check your cups error log:
    sudo gedit /var/log/cups/error_log
    If you see anything like the following, the solution may be simple:
    [Job 201] Unable to write print data: Broken pipe
    PID 13359 (/usr/lib/cups/backend/socket) stopped with status 1!
    System > Administration > Printing and right click on your printer, selecting Properties. Settings > Device URI
    If you see something like socket://your_printer_ip_address:9100 just change socket to lpd and remove the :9100 off the end. Then click on apply.
    Apparently lpd is a more modern protocol which works with most printers whereas socket is more raw (and potentially faster but riskier in a network situation). Somewhere along the line, the default Ubuntu/Gnome setup for networked printers shifted from lpd to socket. Some primitive printers will have benefited whereas a larger number of more modern printers will have suffered.
    Please correct me if I am wrong (which is highly possible) but the underlying problem could be that socket may make the printer wait a long time for a large file to be processed ready for printing. Some printers, such as the Fuji Xerox DocuPrint C525A, may drop the socket if things take too long to start coming through.
    Changing timeout settings might work but lpd is better than socket so it is the preferred solution in any case.
    If this works for you, please leave a comment to let others know (ideally with a description of the printer and Ubuntu version). Printer may be relevant if it doesn’t support the direct stream protocol properly. NB I may take a while to let your comment through because of the volume of spam. Sorry about that.
    Finally, thanks to sphilli8 for the steer in the right direction at http://ubuntuforums.org/showthread.php?p=6245626.
          http://ubuntuforums.org/showthread.php?t=483415

  • Not sure what I've done but clicking on my Mail icon doesn't open my email. Any ideas?

    Looking for help. The mail icon is showing a light. When i click on it doesn't open email - does nothing. Not sure what I've done or what i need to do. Help please.

    Hi...
    Try ctrl+clik the icon and select Quit.
    Then start the app again by clicking the icon.
    /Dennis

  • I am trying to submit the link to the podcast RSS feed but when I press submit I receive the error "We care currently experiencing technical difficulties. Please try again later." I am not sure what I am doing wrong.

    I am trying to submit the link to the podcast RSS feed but when I press submit I receive the error "We care currently experiencing technical difficulties. Please try again later." I am not sure what I am doing wrong.

    I am using http://www.greater-light.org/channel.php?id=3344. I have been trying over a month and I am receiving the same error.
    I am on Windows 7.
    Version iTunes 11.1.4.62.

  • HT1725 I have been trying to purchase points for a slot machine game using my itunes card. It has subtracted all the $$$$ off the card but I never got the points. Not sure what I am doing wrong. Have restarted the ipad and still nothing.

    I have been trying to purchase points for a slot machine game using my iTunes gift card. It subtracted the right about of $$$ but never gave me my points....not sure what I am doing wrong.
    Any help will be appreciated!

    Contact iTune Support
    https://ssl.apple.com/emea/support/itunes/contact.html

  • PLEASE HELP! I AM STUCK..NOT SURE WHAT I AM DOING WRONG! ARGHHHHHH!

    Hello,
    I am a beginner, only recently started Java a couple of weeks ago. For an assignment at uni, I need to create a simple program which allows the user to enter a row number, 5 7, or 9, and depending on the number of row they select, display the letter H and U. (hope that makes sense).
    We need to use several different types of techniques, selection, interaction, loops and methods. I have used all four techniques, but would like to improve the use of the techniques available. One way for me to do this is using a method, i.e. void print_h(), to let the reader know that this piece of code prints the letter h. I've put this method in, above my switch method, but for some reason displays a blank screen. Is this because I have closed the main method? or because I have written the method in correctly?
    I would really reallty appreciate any help...I need to hand this in this week..been working on it a few days now, and I really don't know where I am going wrong.
    import javax.swing.*;
    public class cw
         public static void main (String args [])
              String t_row;
              int row;
              t_row=JOptionPane.showInputDialog(null, "Please enter row number (5, 7 or 9)");
              row=Integer.parseInt(t_row);
         }//i need to close the main method as if I don't I get illegal start of expression error
         void print_h(int row) //i think the error is here, it needs to take the user input from the main method and use it here
              switch (row)
                   case 5:
                             for (int i=0; i<2; i++)
                                       print_x(2);
                                  print_line(3);
                             for (int i=0;i<2;i++)
                                       print_x(2);
                                  break;
                   case 7:
                             for(int i=0; i<3;i++)
                                       print_x(3);
                                  print_line(4);
                             for(int i=0;i<3;i++)
                                       print_x(3);
                                  break;
                   case 9:
                             for(int i=0; i<4;i++)
                                       print_x(4);
                                  print_line(5);
                             for (int i=0;i<4;i++)
                                       print_x(4);
                                  break;
                   default:     JOptionPane.showMessageDialog (null, "Invalid Value, Please try again");
                                  break;
    void print_u(int row)
         System.out.println(" ");
              switch (row)
                   case 5:
                             for (int i=0; i<4; i++)
                                       print_x(2);
                                  print_line(3);
                                  break;
                   case 7:
                             for(int i=0; i<6;i++)
                                       print_x(3);
                                  print_line(4);
                                  break;
                   case 9:
                             for(int i=0; i<8;i++)
                                       print_x(4);
                                  print_line(5);
                                  break;
                   default:     JOptionPane.showMessageDialog (null, "Invalid Value, Please try again");
                                  break;
              public static void print_x(int no_spaces)
                   System.out.print("x");
                   for (int i=0; i<no_spaces; i++)
                        System.out.print(" ");
                   System.out.println("x");
              public static void print_line(int l)
                   for(int i=0; i<l; i++)
                        System.out.print("x");
                   System.out.println("x");
    Here is my code

    Many thanks for that..but I am not quite sure what you
    mean...apologies..i am really new at this...this is
    what I think you mean...
    public static void main (String args [])
    String t_row;
    int row;
    t_row=JOptionPane.showInputDialog(null, "Please enter
    row number (5, 7 or 9)");
    row=Integer.parseInt(t_row);
    print_h();//call print method here?
    this doesn't work still...? any ideas?Do this :
          t_row=JOptionPane.showInputDialog(null, "Please enter row number (5, 7 or 9)");
          row=Integer.parseInt(t_row);
          print_h();//call print method here? YES but with an argument as demonstrated below
         print_h(row); Hope this clarifies things for you...

  • I'm not sure what I've done but I need help please

    Hi everyone.
    I seem to have done something really stupid. In the finder window, I renamed the 'folder' that has the house next to it, from Michaellastname just to Mike. Following that, I went into Front Row to watch a movie saved in my "Movie" folder. Low and behold, Front Row told me that there was nothing saved in that folder, despite the fact that I verified and it was there (I ended up watching it in Quicktime).
    Thinking that I maybe just went about creating another user account, and that if I logged out of this new 'Mike' account everything would be ok. Logging out and logging back in seemed to restore my computer to its original settings ... nothing on the desktop, the dock is the way it was when i took it out of the box, and all my photos and music files etc are missing (well they're still there in that 'Mike' folder, meanwhile 'Michaellastname' still exists). There was no other account to log into other than 'Michaellastname'. Now I don't know what to do ... I would like to move all of my files and settings back to 'Michaellastname' and get rid of the 'Mike' folder, but don't want to try anything on my own because I'm clearly incompetent.
    Can anyone please shed some light on my stupidity and explain how I can fix what I've done? Thank you!

    This is something that happens quite often, so don't feel bad. The ones who should feel bad are the programmers who neglected to have Finder pop a warning when you try to do this, or written code to prevent you doing it at all. It happens so often that Apple provides an article on what to do to fix it:
    http://docs.info.apple.com/article.html?path=Mac/10.4/en/mh1952.html
    Hope that helps.
    Francine
    Francine
    Schwieder

  • I only get the top half of my screen displayed in Safari, not sure what I've done and how to correct it

    I only get the top half of my screen displayed when in Safari, not sure how ths has hapened or how to resolve it, any ideas?

    It's not at the bottom of the screen but the Safari pane/window.  Its very small.  See below.
    Ciao.

  • When uploading photos from my PC to IPad, it gets to the very last stage and then just stops synching.  I've tried multiple times and even from scratch, but same unsuccessful result.  Very frustrating and not sure what I'm doing wrong.

    When synching my photo library (selected folders) to my IPad, it reaches the last (6th) step and then I see the folders appear on my IPad for a brief moment, but then the synch stops and the photos failed to upload.  What's the deal?  After 6 attempts, I give up.  THis should not be that difficult and I've spent way too much time trying to figure this out.  Makes me want to throw out my 1st generation IPad and go with another tablet manufacturer.  Anyone who has experiened this or knows how to remedy would appreciate hearing from you.
    Tx

    Never have this problem. That's just weird. Maybe there's something wrong with one of the photos?
    Try viewing those photos with quicktime first?

  • Windows Update - Not sure what I am doing wrong

    Hello,
    I have SCCM managing updates, but Clients appear to be going to Microsoft for updates. In the local policy on the machine I see that the Primary Server is the update service location.
    If the end user shutdown the computer the gold shield indicating that there are updates to do shows. What could I be missing? I know this may seems small BUT computers are installing updates from Microsoft, and the biggest problem is that IE is updating.
    During OSD which Client Policy is applied? Do I need to disable Software Updates in the Default Client Settings policy? This policy is not applied to any Collection. My policy for the client I am using is applied to the following Collections:
    All Unknown Computers
    All Workstations with SCCM 2012 Client
    Deploy Windows 7 x86/x64
    Deploy Windows 7 x86/x64 Testing
    Any direction would be appreciated.

    I thought I was clear, but will try again. Problem is after OSD clients are retrieving updates from Microsoft. I don't want them to.
    Depending on the combination of settings you have (in your image, in your Domain GPO, in your Local GPO, in ConfigMgr), different things can happen, at different points in time.
    e.g. before ConfigMgr agent has retrieved CM policy about SUM, the WUAgent could be running on defaults/autopilot.
    In our environment, we set the Domain GPO to Disable Automatic Updates (since ConfigMgr doesn't need AU because ConfigMgr instructs WUAgent via API calls, the AU behaviour isn't used at all in ConfigMgr).
    We find this prevents any default AU behaviours, because the Domain GPO is processed and applied almost immediately after the OSD TS is completed. We also "remove all access to WindowsUpdate" via Domain GPO.
    In our environment, the (Windows7/Windows8 equivalent) WU/AU "gold shield" is never, ever seen.
    We have no uncontrolled IE updating occurring.
    We don't allow users to bypass our ConfigMgr/SUM and go direct to WindowsUpdate.com at all.
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)
    If I am understanding you correctly I can disable AU and the Client will still get updates from SCCM? If that is true then my problem is easily solved.
    Domain GPO - Not applying anything
    Local GPO - Not applying anything
    The only thing that is applying is the Config Manager policy.

  • I am trying to create another email account with talk talk. and I keep getting a failed message saying 'mail could not log into the mail server talk talk. Yet I already have another email account with talk talk. Not sure what I am doing wrong

    I am trying to create another email account with Talktalk. I already have one account.
    I try to input the new email address and password and get a failed message
    'Mail could not lot into the mail server talktalk.net.
    I have tried several times and keep getting the same message.
    Any ideas

    Accessing your emails from any computer connected to the Internet or from a Smart phone should be straightforward.
    For help on how to set up your e-mail on some of the most common software applications and devices, see How do I set up my TalkTalk email?
    If your software application or device isn't listed, all you need to connect to your TalkTalk e-mail mailbox are the TalkTalk e-mail settings. Make sure you use the right email settings for your specific email address.
    TalkTalk email addresses only
    Login / Username
    [email protected]
    [email protected]
    Incoming mail server
    mail.talktalk.net
    mail.talktalk.net
    Incoming Port
    110
    143
    Outgoing mail server
    smtp.talktalk.net
    smtp.talktalk.net
    Outgoing Port
    587
    587
    Outgoing SSL
    Yes
    Yes
    Outgoing Authentication
    Yes
    Yes

  • Colour Key/PNG - not sure what I'm doing wrong

    Working an AIC 720/25p project, I've also created a second sequence to use AIC 720/25p, I intend to export from sequence 2 as a video file in order to import it into the original project sequence.
    Sequence 2 consists of a blue matte on v1, a PNG image with transparency on v2 and an MPEG 4 video on v3, which I export to a Quicktime movie.
    Upon import into the original sequence the portion of the video created from the PNG looks a little jaggy around the edges. After applying a colour key to remove the blue background created by the blue matte, it looks substantially more jaggy.
    <a href="http://web.mac.com/gartside1104/Forum Pics/DAr.jpg""target="_blank">
    "Click to View Full Size".
    The QT movie exported from sequence 2 looks fine in QT.
    Using the PNG and the video file directly in the original sequence look just fine, but I can't create the overall effect I'm trying to achieve doing this.
    Message was edited by: Winston Churchill: Oops I've messed up my code, I'll try sort it out, but I need go do something first.

    This isn't the right way to do this. You don't want to try to key a heavily compressed format.
    Create your sequence 2 the way you want it. That without rendering it, or making sure it is un-rendered, export to QuickTime Conversion. Set the codec to Animation. Make sure colors are set to millions+. This will export the sequence with a clean alpha channel, which you can reimport into FCE and composite over your media.

Maybe you are looking for

  • Oracle data from 9.2.7 to oracle 10.2.2

    Hi, I have upgraded sap from 46C to ECC6 with oracle 10.2.0.2 and has given the system for testing. Current production server is on 46 with oracle 9.2.7. Complete testing is completed on the upgraded ECC version. Now i have to move the live productio

  • Hard drive complete back up

    received an imac g3 from a friend with no hard drive, bought a used one that is empty formatted hfs+. this is for my daughter in her bed room, she will be on the net. i have the same exact model running 10.3.9. i want to copy or clone my hard drive t

  • Possible Bug in Mail.app

    I am running a server and clients -- all at 10.4.4. The mail app on the clients Version 2.0.5 (746/746.2). I have been tracking down errors in my imapd log file. The errors are: Feb 5 00:18:05 EaseServer imap[23046]: IOERROR: reading message: unexpec

  • Bad string error!

    hello, for my application, I am using combo box for displaying IP addresses. when i go to that corresponding panel from Main Menu buy clicking 'GoToIPdiplay' menu item, the output throughs "Object Identifier: bad string supplied to set value " error

  • Doubt regarding Transporting Design Objects

    Hi all, While transporting the design objects from DEV to QAS, iam doing in the following way 1) i am doing transport Namespace wise individually and exported one by one.These all interfaces involved with IDOCs 2) When i import into Quality Design, i