Results 1 to 2 of 2
  1. #1
    Juulis is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Program don't work as expected.

    Hi! I'm just learning Java for fun and found this forum very usefull some of the time! :)

    Now, I have a problem, I can't get an application to do what I want it to do..
    I just want it to run "choice" , then from my input choice I want it to run e.g ovning3 (which is "converter") but it just exits after I type in my choice "3" ..

    Anything I did wrong? This is my first app with several "instances".. My logic is wrong?

    Thanks // Juulis

    Java Code:
    import static javax.swing.JOptionPane.*;
    public class Ovningar {
    	public static void main(String[] args) {
    	public static void choice(){
    		String input = showInputDialog("Välj övning");
    		if (input == "3")
    		if (input == "4")
    	public static void sfer() {
    	public static void converter() {
    		String input[] = showInputDialog("Mile/Gallons?").split("/");		
    		String strmiles = input[0];
    		String strgallon = input[1];
    		double miles = Double.parseDouble(strmiles);
    		double gallon = Double.parseDouble(strgallon);
    		double km = miles*1.609;
    		double liter = gallon*3.785;
    		showMessageDialog(null, km+"/"+liter);

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Program don't work as expected.

    Don't use == when comparing Strings or Objects unless you want to decide whether two Objects are the same exact instance. To compare equality, use the equals() method. Do a search on google or these forums for a better explanation of why that is.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Update doesn't work as expected?
    By RexBox in forum New To Java
    Replies: 3
    Last Post: 10-06-2012, 05:54 PM
  2. Program does not work if I put it online
    By Maarten in forum New To Java
    Replies: 9
    Last Post: 08-02-2012, 08:57 PM
  3. program compiles but does not work
    By alara in forum New To Java
    Replies: 4
    Last Post: 11-27-2011, 08:47 PM
  4. Trying to work out this program
    By KidneyinaCooler in forum New To Java
    Replies: 6
    Last Post: 07-18-2010, 03:14 AM
  5. Program don't work
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-04-2007, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts