Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    18
    Rep Power
    0

    Default this wont run again and again?? why?

    i made a program it runs correctly but it wont repeat as i set a do while loop why?? here is the code

    Java Code:
    import java.util.Scanner;
    
    public class main {
    
        static String af = "0";
        static String bf = "0";
        static String ff = "0";
        static String mn = "0";
    
        public static void main(String args[]) {
    
    
            do {
    
    
    
    
                final double R = 1.0967 * (10000000);
    
    
    
    
    
                double lowest = Double.parseDouble(af);
                double highest = Double.parseDouble(bf);
                double answer = Double.parseDouble(ff);
    
    
                Scanner obj = new Scanner(System.in);
    
                System.out.println(
                        "Insert the lowest Energy level");
    
    
                lowest = obj.nextDouble();
    
    
    
    
                System.out.println("Now,Insert Highest Energy level");
                highest = obj.nextDouble();
                answer = R * (1 / (lowest * lowest) - 1 / (highest * highest));
    
    
                System.out.println("Wave Length is  " + 1 / answer);
    
    
                System.out.println("Do you wish to continue? y ? or n?");
                mn = obj.next();
                
    
            } while (mn == "n");
    
    
    
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Don't compare Strings with ==. Instead use the equals(...) method.

    The reason that this is important is that == checks if one object is the same as another object, and that's not what you care about here. Rather you want to check if one String has the same characters as another String and that's what the equals method does.

  3. #3
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    Java Code:
    do
    {
    
    
    System.out.println("Do you wish to continue? y ? or n?");
     mn = obj.next();
    
    }while(mn.equalsIgnoreCase("y"));

Similar Threads

  1. .jar wont run?
    By stevenpalomino in forum New To Java
    Replies: 1
    Last Post: 06-30-2011, 10:11 AM
  2. Why Wont This Work???
    By Billywizz in forum New To Java
    Replies: 11
    Last Post: 03-09-2011, 02:33 AM
  3. why wont the %.2f work here?
    By jjth39347 in forum New To Java
    Replies: 2
    Last Post: 03-06-2011, 05:55 AM
  4. Able to compile OK, But wont run..Help
    By subiedude101 in forum New To Java
    Replies: 2
    Last Post: 02-20-2011, 08:37 PM
  5. Why wont this compile?
    By Student101 in forum New To Java
    Replies: 8
    Last Post: 11-18-2010, 05:33 AM

Posting Permissions

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