I don't understand why this simple program will not print.  Help please!!!

This program runs with no errors, it just doesn't print anything. Anyone have a clue as to why it doesn't print anything?
Here is my code:
import javax.swing.JOptionPane;
public class Converter {
public static void main(String[] args) {
int a,b,c;
int inputNum=Integer.parseInt(JOptionPane.showInputDialog(null," Enter a length in yards: "));
String measurement = JOptionPane.showInputDialog(null,"Enter the unit of conversion (inches, feet, or centiyards): ");
if (measurement == "inches"){
a = inputNum*36;
System.out.println(a + "inches");
else if (measurement == "feet"){
b = inputNum*3;
System.out.println(b + "feet");
else if (measurement == "centiyards"){
c = inputNum*100;
System.out.println(c + "centiyards");
}

Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same character sequence), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out the Java FAQ
~

Similar Messages

  • I don't understand why this recursive program is looping, or its #s.

    i put in a println around the 7th line of code to see how it is working, i dont understand how to app is getting its numbers or why it is looping without a for statement. this demonstrates
    recursion. the output i get is
    value of n is 2
    value of n is 3
    Factorial of 3 is 6
    value of n is 2
    value of n is 3
    value of n is 4
    Factorial of 4 is 24
    value of n is 2
    value of n is 3
    value of n is 4
    value of n is 5
    Factorial of 5 is 120
    How is this possible when the only arguments passed in are 3, 4 , and 5, so that (n-1)*n would result in 6, 12, and 20. or at least thats what i thought it would produce, but instead,
    it loops through 2 3 4 5 and i have no idea where its getting those numbers from. any help greatly appreciated.
    public class Factorial {
          // this is a recursive method
         int fact(int n){
          int result;
         if(n==1) return 1;
         result = fact(n-1) * n;
         System.out.println("value of n is " + n);
         return result;
          class Recursion {
               public static void main(String args[]) {
                    Factorial f = new Factorial();
                    System.out.println("Factorial of 3 is " + f.fact(3));
                    System.out.println("Factorial of 4 is " + f.fact(4));
                    System.out.println("Factorial of 5 is " + f.fact(5));
          }

    Recursion is closely related to the mathematical principle of proof by induction.
    You use induction to see that your recursive method is correct. Take the factorial method
    of the OP:
    int fact(int n){
        if(n==1) {
            return 1;
        } else {
            return n * fact(n-1);
    }Some peoples' heads explode when they see a method invoking itself, as though they were
    seeing a snake swallowing its tail and disappearing! Yet nothing could be simpler or more
    logical. These same people have no problem when f() calls g(), so suppose the previous
    code had been written:
    int fact(int n){
        if(n==1) {
            return 1;
        } else {
            return n * SOMEBODY_ELSES_FACTORIAL(n-1);
    }Now we are just looking at ordinary code. Suppose method SOMEBODY_ELSES_FACTORIAL
    does indeed compute the factorial function. In order to implement X you need to
    know something about X, right? So we need to know a few things about factorial. These are:
    1! = 1
    n! = n * (n-1)!, for n>1
    By inspection, our code handles the n=1 case, and because we assume SOMEBODY_ELSES_FACTORIAL works,
    it handles the case n>1 successfully, too.
    Finally, the principle of induction tells us SOMEBODY_ELSES_FACTORIAL can in fact be the method
    we are defining, fact().
    QED

  • Ok so heres my question. I don't understand why this sign that say "Terms n Policy of the store have changed!" and it said to go agree the new terms and policy. I did that and it went back to the app store,but then it pops out again! What do i do?!

    Ok I don't understand why this sign that says "Terms and Policy of App store has changed!" So it tells me to go agree the new terms and policy. After i did that it returns to the App Store where i was before. And only like ten to five seconds it appears again! I just dont know what to do! Can anyone help me?!

    Sign out of iTunes and sign back in and try again. The issue is being reported as being solved....
    GB

  • Why this simple assingment is not possible in Generics ?

    Hi
    Just curious to know why this simple conversion does not work and requires casting ?
    List<? super Integer> list = new ArrayList<Integer>();
    List<? super Number> listN = list; //Requires Casting
    List<? extends Number> listExNu = new ArrayList<Number>();
    List<? extends Integer> listExIn = listExNu; //Requires CastingAs per my understanding ,
    A List<? super Number> can fit inside a List<? super Integer> ...
    So what really happens here to force casting ? Any ideas ?

    ejp wrote:
    List<? super Integer> list = new ArrayList<Integer>();The only two classes that are superclasses of Integer are Number and Object.Not quite. Please note that the clause *? super Integer* is inclusive, i.e. it also matches List<Integer>.
    Additionally, it matches all interfaces implemented by Integer. Thus, the following types can be assigned to list:
    List<Integer>
    List<Serializable>
    List<Comparable<Integer>>
    List<Comparable<? extends Integer>>
    List<Comparable<? super Integer>>
    List<Comparable<? extends Number>>
    List<Comparable<? extends Serializable>>
    List<Comparable<?>>
    List<Number>
    List<Object>And the following types can be assigned to listN:
    List<Serializable>
    List<Number>
    List<Object>Since the latter is a genuine subset of the former, an implicit conversion such as listN = list is impossible.

  • Every time I try to open Photoshop Elements 12, it opens the Adobe login, after I login the program does not open:( Help please?

    Every time I try to open Photoshop Elements 12, it opens the Adobe login, after I login the program does not open:( Help please?

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • I was able to get the program to install last weekend but I had to do a refresh on my computer and THe program will not install.  Please help

    I was able to get the program to install last weekend but I had to do a refresh on my computer and THe program will not install.  Please help

    Please read, and reply here with more information https://forums.adobe.com/thread/1499014

  • Quickbooks program will not print reports.  I think it is an Adobe/Pages issue but I don't know how to resolve it.  Help!!!

    Quickbooks reports will not print.  I think it has something to do with Adobe/Pages \but I don't know how to fix the issue.  Help!

    I don't see how it could have anything to do with any Adobe app or Pages. QuickBooks is its own thing and does not rely on any other apps to print.
    I opened a couple of random reports and had no trouble sending it to a laser printer. Also no issue saving them to text file, or clicking the Export button at the top right of the report and having it open directly into Excel.
    What exactly are you trying to accomplish, and what is failing?

  • Can someone help me understand why the search engine will not do anything when I click the search icon or press enter, and why new windows won't open when I click on a link that should open one?

    When I type something in the search engine at the right hand corner of the screen it will not allow the search to take place. What I mean is I either click the icon or press enter and nothing happens. I would understand it better if it at the very least gave me a error message. I have also noticed that things like the opening of a new window via a link will not work. An example is I was just on www.walmart.com and when I clicked on an image in order to see a larger one no window opened. I also recently noticed that when I had a lot of tabs open the shortcut menus and menus in general did not load completely or really at all keeping me from saving the pages as bookmarks. I know this could be from low internet speed, a lot of tabs etc..., but I've had many more tabs open than I had then and it worked. Plus all I did was delete or close one tab and suddenly it worked. I then recovered the tab and it still worked even though I was back at the original amount of tabs. I have the latest version of firefox, not counting the beta, and I don't know of any way to solve the two main problems.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • 8.0 applicatio​n builder problem- very simple programs will not install on non LV machine

    Newbie at this...
    1.  Created a simple project (just math) in LV 8.0
    2.  Did the build
    3.  Built an installer but Deselected  RTE installer as I told my customer to download LV RTE 8.0
    4.  The installer put everything into a file folder called VOLUME... (?)
    5.  Copied VOLUME over to non LV machine that had LV 8.0 RTE downloaded and installed.
    6.  Ran ithe NI nstaller on non LV machine.  Ran Ok.
    7.  However,  no files were installed (checked the PROGRAMS directory).
    This is a REAL simple program.  Can anyone point me to some simple/stupid thing I did wrong?
    frustrated in San Diego....
    John

    John:
    Looking at all your steps, it seems like you are doing all the right things and in the right order too. Couple of things that you may try:
    1. Make sure that in your installer properties, you specify "ProgramsFileFolder" in the Source Files tab if you want your installer files to be  
        placed under "...\Programs\" (Please take a look at the attached screenshot)
    2. Try building an executable and make sure that you can run on the customer's computer (since it already has the LabVIEW Run Time Engine)
    Let me know what you find.
    Regards,
    Rudi N.
    Attachments:
    Installer.JPG ‏52 KB

  • Every time I open my homepage (not the Firefox page), another tab opens that is an ad. My pop-up blocker is on, so I don't understand why this is happening.

    My homepage is whitenoiseplayer.com. Whenever I open Firefox, this additional tab opens. It is an ad that says something like, "Congratulations Wal-Mart customer!" and says I've won something. I don't think it's a virus, because I already did a virus scan. Could it be a problem with my homepage? I've been using this homepage for quite some time, and this has never happened before. It doesn't happen when I open any other websites.

    This kept on happening to me too! I finally figured out the problem! I had downloaded something and it set it as my homepage automatically. Only mine was a google search of something and it was highly annoying, but the same problem! At the top of mozilla push firefox>options>options>general. Look at the homepage part.
    It should only have your chosen homepage, but it doesn't! Just delete the other link and press save! I guess firefox allows you to have as many home page's as you like! Odd, but cool.
    Well, I hope that helped! (:

  • I don't understand why this thread is blocked

    We have several hundred unit tests that we run very frequently on our application, which uses BDBJE. In the last month or so, we've suddenly had unit tests start randomly hanging on the following stack trace. Can anyone help me understand what we're doing wrong? What is this lock doing? This is the ONLY thread that is doing anything in sleepycat classes.
    Thanks!
    "main" prio=10 tid=0x0000000040df5800 nid=0x29c1 in Object.wait() [0x00007f7eeb712000]
    java.lang.Thread.State: WAITING (on object monitor)
         at java.lang.Object.wait(Native Method)
         at com.sleepycat.je.txn.LockManager.lockInternal(LockManager.java:346)
         at com.sleepycat.je.txn.LockManager.lock(LockManager.java:272)
         - locked <0x00000007a48c0918> (a com.sleepycat.je.txn.BasicLocker)
         at com.sleepycat.je.txn.BasicLocker.lockInternal(BasicLocker.java:134)
         at com.sleepycat.je.txn.Locker.lock(Locker.java:453)
         at com.sleepycat.je.dbi.CursorImpl.lockLNDeletedAllowed(CursorImpl.java:2695)
         at com.sleepycat.je.dbi.CursorImpl.lockLN(CursorImpl.java:2615)
         at com.sleepycat.je.dbi.CursorImpl.searchAndPosition(CursorImpl.java:2267)
         at com.sleepycat.je.dbi.DbTree.lockNameLN(DbTree.java:692)
         at com.sleepycat.je.dbi.DbTree.doRemoveDb(DbTree.java:849)
         at com.sleepycat.je.dbi.DbTree.dbRemove(DbTree.java:896)
         at com.sleepycat.je.Environment.removeDatabase(Environment.java:953)

    I've been wrong before, but the stack trace is a very strong indication that you've not closed a Database handle. Note that if you call openDatabase more than once, you must close each handle.
    If the lock timeout is zero, then I believe you're setting it to zero, because the default is not zero.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • My iPhone 4gs won't let me download any apps because the security code is invalid? I enter everything correct and my address, don't understand why this is happening! Help please

    I just need to be able to download apps and my phone keeps saying the security code is invalid which doesnt make sense because I enter everything correct and it's really fustrating I've been to the apple store I've called support and they can't seem to fix it! Can somebody please help me? I thought apple was suposta be easy to use :\

    This can sometimes happen because there is a missmatch between the billing address entered on your iTunes account and the billing address from your bank records.  See http://support.apple.com/kb/TS1646.

  • Hi I have purchaed 7500 T- Coins for tetris and every time i play i have no poer coins i don't understand why this keeps happening Please let me know if maybe im not doing something right otherwise i would like a refund as these T- coins are doingnothing

    As i said i purchased 7500 T-coins for tetris and i run out of ower coin in seconds the T-coins seem to NOT be doing anything to help my game if that is the case i want to cancel my orders for a refund .Maybe i am using them wrong or they didnot kick in please let me know  Thank You Laura

    There is no configuration of a MBP that will satisfy the needs of all users.  The variables are too many for the tasks that are required for the MBP to perform.
    If cost is no object, the fastest CPU is a given as well as RAM.  Needs for same may be few and not often if ever used, but certainly will do no harm,
    Storage is an issue of a HDD with greater capacity compared with the speed offered by SSD with lesser capacity.
    Size can be important.  The convenience of portability of a 13" MBP with the larger and heavier 15" and 17' MBPs.
    In the final analysis, you have to make these decisions.
    Ciao.
    (I'm not an expert)

  • I don't know how to get help. Since yesterday 17th October, my Mac is refusing to open copied documents. I can't work, and I don't  understand why this has suddenly happened, or how to stop it. HELP PLEASE

    Dear Mac users, could you please tell me how to get Mac technical support. Thank you very much.

    If you are still under warranty, you can call AppleCare. If not, you can still call them and pay a fee for service.
    Or, you can further explain your problem here and we will try to help.
    What error messages are you getting.
    Where are you copying from and to?

  • I have an MPEG4 movie running.  I don't know why but Quicktime Player will not let me open this file now to shut it down.  Any tips on how to do this?  I've tried installing an older version QuickTime Player 7.  OS Maveriks

    I have an iMac with an OSX 10.9.5.  I have an MPEG4 program that is running.  QuickTime Player can't open it up for me to stop it.  What are my options?  I've tried downloading QuickTime Player 7, an older version but that hasn't helped.

    Not sure what you mean then. Is QuickTime still open and playing the video? If so, do you mean you can't even get back to QT to shut it down?
    Check the Dock for the QT logo. Click it to bring that app to the foreground. The menu bar then should say QuickTIme Player next to the Apple logo. Close the app and the video will shut down with it.

Maybe you are looking for

  • Saving Opened attachments in a secure environment (no local drive access)

    We are evaluating Windows 7 and Office 2010 in a secure environment and have a strange issue when saving opened Office attachments from Outlook 2010. If an Office (Word, Excel or Powerpoint) file is opened from a received email within Outlook 2010 an

  • Are there Apps to use the iPad in a lab

    I work in a research medical lab. Usually I write experiments and data in a lab notebook where I can describe experiments and draw figures by hand and record data. My Question: Are there APPS available for the iPad that would allow me to do this with

  • ITunes setup not opening or installing.

    I downloaded iTunes setup, but when it's finished and I click on it to install it, it doesn't open. I've tried a number of different ways to open it, even downloading it again..but nothing works. And when I try to delete it, it says it cannot delete

  • Special Characters Report Painter

    Hi all, After SP 2008 implementation on ECC 5.0, special characters as : "( " ; "= "; "+" ; etc... are not recognized for one digit in report painter library. After analyse, without changing size colums, if the title contain a special character, it i

  • [gave-up] Connecting with username and password with nmcli

    I'm trying to connect to my university's network via nmcli. They give instructions on how to connect using the gui'ed version of Network Manager, however this is neither desired, nor at the time available to me. I've read through the wiki as well as