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

    Default i cant run this program pls help???

    import java.util.Scanner;

    public class main {

    static String af;
    static String bf;


    public static void main(String args[]) {

    final double R = 1.0967 * (10000000);





    double lowest = Double.parseDouble(af);
    double highest = Double.parseDouble(bf);
    double answer;


    answer = R * (1 / (lowest * lowest) - 1 / (highest * highest));

    System.out.println(
    "Insert the lowest Energy level");
    Scanner obj = new Scanner(System.in);
    af = obj.nextLine();
    System.out.println("Now,Insert Highest Energy level");
    bf = obj.nextLine();
    System.out.println("Wave Length is " + answer);


    }
    }

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

    Default

    Please see the link in my signature on asking smart questions, and please use CODE tags when posting code. What's your question?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    SuperPig is offline Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0

    Default

    why did you use static on String af and bf? and yet you didnt assign any value for them.
    consider this sequence:
    1. i declare a String without assigning any value to it.
    2. i convert "empty value" string to double..~
    how can one person convert no value into a value..~

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by SuperPig View Post
    convert "empty value" string to double
    An empty String and null are not the same thing
    Java Code:
    String s1; // null
    String s2 = ""; // empty String
    
    System.out.println(s1.length()); // NullPointerException
    System.out.println(s2.length()); // displays 0
    
    Integer.parseInt(s1); // NullPointerException
    Integer.parseInt(s2); // NumberFormatException
    
    System.out.println(s2.equals(s1)); // displays false
    System.out.println(s1.equals(s2)); // NullPointerException

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    @op: don't double post threads: null value exceptions

  6. #6
    SuperPig is offline Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    An empty String and null are not the same thing
    Java Code:
    String s1; // null
    String s2 = ""; // empty String
    
    System.out.println(s1.length()); // NullPointerException
    System.out.println(s2.length()); // displays 0
    
    Integer.parseInt(s1); // NullPointerException
    Integer.parseInt(s2); // NumberFormatException
    
    System.out.println(s2.equals(s1)); // displays false
    System.out.println(s1.equals(s2)); // NullPointerException
    sorry sorry..~ i have forgotten the term - null...

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Null means uninitialized and makes some variable "empty". You can't do much with null variables or else you will get exceptions.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by sunde887 View Post
    Null means uninitialized and makes some variable "empty".
    The point I was trying to get across is that a variable is never empty. It always holds a value. If you do not assign a value to an instance variable then it gets a default value. For primitives it gets the corresponding default value: int, long, double, float etc get 0, char gets the null char '\0' boolean is false and for reference types (ie object variables) the default value is the null reference.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    OK I just realised that local variables can be unitialised and can be thought of as empty. But you still can not use them as the compiler will complain.

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •