Help with Double.NaN

This class is supposed to check how many real numbers are being sent to All and depending on that perform further operations with those numbers.
It works just fine if all four number are present, but if one number is missing (i.e. fourth number in n2 in main), when it goes to All the first condition is ALWAYS true, even though it says if the number is not NaN it just skips it and goes to AllN with four numbers. Am I not using Double.NaN right?
public class Numbers {
public double num1 = Double.NaN, num2 = Double.NaN;
public double num3 = Double.NaN, num4 = Double.NaN;
public double first = Double.NaN, second = Double.NaN;
public double third = Double.NaN, fourth = Double.NaN;
public String snum0;
// accessor methhods
public void setNum1 (double value) {
num1 = value;
public void setNum2 (double value) {
num2 = value;
public void setNum3 (double value) {
num3 = value;
public void setNum4 (double value) {
num4 = value;
public double getNum1 () {
return num1;
public double getNum2 () {
return num2;
public double getNum3 () {
return num3;
public double getNum4 () {
return num4;
public double getFirst () {
if (first != Double.NaN)
return first;
else
return Double.NaN;
public double getSecond () {
if (second != Double.NaN)
return second;
else
return Double.NaN;
public double getThird () {
if (third != Double.NaN)
return third;
else
return Double.NaN;
public double getFourth () {
if (fourth != Double.NaN)
return fourth;
else
return Double.NaN;
public void All (Numbers s) {
if (s.num4 != Double.NaN &&
s.num3 != Double.NaN &&
s.num2 != Double.NaN &&
s.num1 != Double.NaN)
AllN(s.num1, s.num2, s.num3, s.num4);
else if (s.num4 == Double.NaN &&
s.num3 != Double.NaN &&
s.num2 != Double.NaN &&
s.num1 != Double.NaN)
AllN(s.num1, s.num2, s.num3);
else if (num4 == Double.NaN &&
num3 == Double.NaN &&
num2 != Double.NaN &&
num1 != Double.NaN)
AllN(num1, num2);
else if (s.getNum4() == Double.NaN &&
s.getNum3() == Double.NaN &&
s.getNum2() == Double.NaN &&
s.getNum1() != Double.NaN)
AllN(num1);
else if (s.getNum4() == Double.NaN &&
s.getNum3() == Double.NaN &&
s.getNum2() == Double.NaN &&
s.getNum1() == Double.NaN)
AllN();
}// end SortAll
public void AllN() {
snum0 = "There are no numbers to sort";
public static void main (String args[]) {
Sort n1 = new Sort();
n1.setNum1(13);
n1.setNum2(14);
n1.setNum3(15);
n1.setNum4(16);
n1.SortAll(n1);
Sort n2 = new Sort();
n2.setNum1(57);
n2.setNum2(34);
n2.setNum3(50);
n2.SortAll(n2);
System.out.println(n1.getSecond());
System.out.println(n2.getFirst());
} // End Main

double v = 5.0;
if (v == v) {
  System.out.println("v is a number: "+v);
} else { // (v != v)
  System.out.println("v is not a number: "+v);
// or
if (Double.isNaN(v)) {
  System.out.println("v is not a number: "+v);
} else {
  System.out.println("v is a number: "+v);
}

Similar Messages

  • Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.

    Before I go into a lengthy explanation of the problem: Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.
    Thanks much.
    Emile

    Choose Force Quit from the Apple menu and close Mail from there.
    (103661)

  • Need help with doubles

    I need help with a double cheeseburger. I want one for lunch but am not hungry enough to eat it all. Who wants half?
    We can split some Walker's crisps, too.

    public class DoubleCheeseburger extends Hamburger
      implements AnnoyanceOfAnimalRightsAdvocates
       boolean bacon;
       public DoubleCheeseburger()
          bacon = false; //explicitly don't want bacon
       public DoubleCheeseburger(boolean bacon)
          this.bacon = bacon;
       public boolean splitIt(int portions)
          boolean cleanSplit = true;
          System.out.println("Splitting the food into wedges of "+(360/portions)+" degrees each.");
          if (bacon = false)
             System.out.println("No need to worry about splitting the bacon slices.");
             cleanSplit = true;
          else
             System.out.println("Someone may not get enough bacon.");
             cleanSplit = false;
          return cleanSplit;
    }

  • Help with double buffer

    I have a series of images that I display on a jLabel using imageIcon that get loaded depending on the mouse position on the label. I would like to preload these images somehow so that there is no wait time for the user when these images are called up. It seems that the doublebuffer object might help with this but I am not sure how....Any help appreciated..
    Jacques

    Well you can create an array of Image Icons and put you images there ...
    ImageIcon[] myImages = new ImageIcon[number_Of_Images]; -MaxxDmg
    - ' He who never sleeps...'

  • Help with doubles and intergers

    I'm new to JAVA programing. So, I'm hoping that someone can help me. Below is part of my code that I'm having a problem with.
    int gold, total
    double percent
    percent = ((gold / total) * 100)
    comes out looking like 0.0
    Is there a way to define (gold / total) as a double in the math statement?
    Thank you for all your help,
    Jennifer

    The problem is integer division always produces an integer, so for example:
    1 / 2 == 0, not 0.5
    but:
    ((double) 1) / 2 == (approximately, allowing for IEEE floating point precision errors) 0.5
    same for 1 / ((double) 2) or using literal constants like 1.0 / 2

  • Need help with double buffering

    Hi!
    I'm trying to write an animated applet the shows the Java Duke waving.
    No problem getting it to work, but the applet is flickering and I sence the need for double buffering.
    I've tried to use "traditional" double buffering techniques without success. Something like this:
    currentDuke = bufferGraphics.getGraphics();
    public void update(Graphics g) {
        bufferGraphics.clearRect(0, 0, this.getWidth(), this.getHeight());
        paint(g);
    public void paint(Graphics g) {
        bufferGraphics.drawImage(nextDuke, 0, 0, this);
        g.drawImage(currentDuke, 0, 0, this);
    }Didn't help...
    Here's my current code:
    import javax.swing.*;
    import java.awt.*;
    * This is a simple animation applet showing Duke waving.
    * @author Andrew
    * @version 1.0 2002-07-04
    public class WavingDuke extends JApplet implements Runnable {
        private Image[] duke;
        private Image currentDuke;
        private Thread wave;
         * Called by the browser or applet viewer to inform this applet that it has
         * been loaded into the system.
        public void init() {
            loadDuke();
            currentDuke = this.createImage(this.getWidth(), this.getHeight());
         * Called by the browser or applet viewer to inform this applet that it
         * should start its execution.
        public void start() {
            if (wave == null) {
                wave = new Thread(this);
                wave.start();
         * Loads all the duke images into a <code>Image</code> array.
        private void loadDuke() {
            duke = new Image[10];
            for (int i = 0; i < 10; i++) {
                duke[i] = this.getImage(this.getCodeBase(), "images/duke"+i+".gif");
         * Method cycles through different images and calls <code>repaint</code>
         * to make an animation. After each call to <code>repaint</code> the thread
         * sleeps for predefined amount of time.
        public void run() {
            while (true) {
                for (int i = 0; i < 10; i++) {
                    currentDuke = duke;
    repaint();
    paus(150);
    * Method makes the current thread to sleep for tha amount of time
    * specified in parameter <code>ms</code>.
    * @param ms The time to wait specified in milliseconds.
    private void paus(int ms) {
    try {
    Thread.sleep(ms);
    } catch (InterruptedException ie) {
    System.err.println(ie.getMessage());
    * Updates this component.
    * @param g The specified context to use for updating.
    public void update(Graphics g) {
    paint(g);
    * Paints this component.
    * @param g The graphics context to use for painting.
    public void paint(Graphics g) {
    g.clearRect(0, 0, this.getWidth(), this.getHeight());
    g.drawImage(currentDuke, 0, 0, this);
    Thanks in advance!
    /Andrew

    I've solved it!
    /Andrew

  • Help with double and float

    I added the (float) after the = in both and it fixed the top and not the bottom. "cant convert double to float" (as well as the answer to this, if somone could correct my terminology as well it would be appretiated. thanks in advance)
    float torontoF = (float)(torontoC * 1.8) + 32;
         System.out.print (torontoF);
    x      float stockholmC = (float)(stockholmF ? 32)* .5556;
         System.out.print (stockholmF);

    Reposted and answered at:
    http://forum.java.sun.com/thread.jspa?threadID=5219089
    Do not reply here.

  • Plese help me ! can't open files with double clicking icons...

    at the first, sorry about my English. (i'm japanese and english is my second language so..) anway.... i can't open the files on desk top by double click. if i go to Finder then i can open files... and some files i can open by double click. i downloaded Limewire but i can't install it because my couble click is not working for that. but i can double click to open photoshop, safari or email or some other things in the dock. and i couldn't open up the games either.. doesn anybody knows what's happened to my son's computer? it's a iMac flat panel G4. and OS X 10.3.9. Thank you sooo much!!

    Saw your response and started to write to you for help also but have, with one final try, found PART of my problem. I have a Logitech wired optical mouse that worked with everything except opening desktop volumes when I double clicked on them. I could open applications and documents within the Finder window....just not the desktop volume icons.
    I ran Disk Utility........verified all the volumes........repaired all permissions, unplugged mouse and reset. Logitech software is up to date.. I've never had this happen before.
    What I discovered was that I was double clicking to open the volumes, but had the mouse set for single click. It's still a little strange because I changed it to double click to open and now it opens with double OR single click. Now I can open the volumes but it won't allow me to move the Finder windows that open. I can't drag or move them on the desktop; have to use them where they open.
    Any suggestions for me, I hope? Thanks.

  • Help needed with doubles and integers

    I just want to start telling all you that you have been a big help to me the last couple of months. Now, for my issue. I'm having a problem doing some work with doubles and integers. Below is the code I've tried. But, I keep getting mismatch types. I need num3 to fill in a JTextField by the end with the answer for the calc. Num2 is fill in from a JTextField with a double.
    Int num1 = 0, num4 = 0, num3 = 0;
    double num2 = 0, totint = 0;
    for(count = 0; num4 < count; count++)
    totint = (1 + num2);
    System.out.println(totint);
    num3 = double (num1 * totint);
    String k = Integer.toString(num3);
    tf3.setText(k); (This is a JTextField)
    Test data
    num1 = 10000
    num2 = 3.4
    num4 = 4
    num3 = the value from the calc

    First of all, your for loop is never going to run.
    for (count = 0; num4<count; count++)
    totint = (1 + num2);
    System.out.println(totint);
    num4 = 4 and will not be less than count, so the for loop will not be executed.
    Second, what exactly are you trying to accomplish here. The way you have your code set up, the for loop (if it were to execute) would print out 4.4 each time it passes, then do the calculation. You may need to rethink your objective.

  • HT201318 Need help with being double charged on my icloud account when purchasing extra storage for my ipad

    Need help with being double charged on my icloud account when purchasing extra storage for my ipad?

    I had this same problem on my 4S. I fixed it by restoring the phone to factory defaults. Previously, I had taken the additional step of restoring from backup but, as soon as I did, the problem returned. The fix is a hassle as I now have to reinstall my apps but at least I can manage mail on the phone.
    The problem also occurred on my iPad2 but I'm not restoring it as it's a serious hassle (see above) and I don't actually read much mail on the device.
    As a side note, I noticed incredibly high load averages (5+ processes for 1, 5, and 15 minutes; 12+ for 1 and 5 minutes at one point) as well as CPU usage that didn't drop below 15% (apparently all user processes, system seemed to be about normal). As could be expected, this also lead to incredibly rapid battery depletion.
    I can't tell what processes were hogging the CPU as neither of my devices are jailbroken and Apple doesn't seem to like 'top' much.

  • File Protocol does not work with double slash ...PLEASE HELP

    Hi ALL
    POSTING THIS AGAIN....Please have alook
    I am using j2sdk 1.4.2 . In 1.4.1 version File protocol was working with double slash
    But Now in 1.4.2 version I have to use /// slashes to make it work...
    Can anyone shed any light on this. Has Sun changed something ?
    I searched the release notes but could not find anything useful.....
    Please comment .
    Thanks

    The problem is that it leads to maintenance problems
    for our products
    future releases and I need to find a good solution to
    this problemRead the spec for file URLs, fix your existing code to use it, and remember this lesson for next time.
    (Side note: I can't remember ever using or seeing double slases.)

  • Hi guys, need your help with iCloud notes on Mac 10.7.5; I've found this feature's more useful comparing with stickers, however can't pin notes to desktop or dock, "double click"on the note doesn't work with this version of software.

    Hi guys! Need you help with iCloud Notes on Mac Pro 10.7.5. I've found this apllication more useful comparing with "stickers", however can't pin it to desktop or dock. Thanks a lot in advance!

    Hi guys! Need you help with iCloud Notes on Mac Pro 10.7.5. I've found this apllication more useful comparing with "stickers", however can't pin it to desktop or dock. Thanks a lot in advance!

  • Be grateful for your help with Photoshop Elements which I have been using for several years.

    Be grateful for your help with Photoshop Elements which I have been using for several years.  Does Elements need to have access to ‘My Pictures’ on Windows as when I remove Photos from ‘My Pictures’, Elements later, when backing up, gives a message that it is unable to ‘reconnect’ to the same picture on elements.  On other occasions when removing a photo from Elements catalogue I also get a similar message when backing up saying ‘unable to reconnect’.  1. Is there a relationship between Elements and My Pictures and is Elements dependant on    the Windows ‘My Pictures’? 2. Why does some photos in Elements in some cases cause them to multiply e.g. double; triple; quadruple; and on occasions even more?  Is there something I need to do to stop this or an easy way I can remove the multiples without spending hours doing it manually one by one?  Am I doing something wrong? My O/S is Windows XP SP2 and windows Vista on my Laptop.  I have been using Elements 5 and have just purchased Photoshop Elements 8.0. (Upgrade) and about to install it. Be grateful for any advice as I do enjoy using the program if only I can resolve this issue.  I am not a PC wiz and mainly use Elements to catalogue photos from which I compile collections and from them slide shows with music.  Any advice appreciated Sonny.t PS Have tried to post this previously but without success so hoping to see message appear and a +response

    The organizer doesn't care where you send your photos when you download them via the downloader or where they happen to be when you first bring them in if you use the Get Photos command, but once your pics are in the Organizer, you *must* move them from within organizer or it can't find them. You don't have to use My Pictures at all if you don't want to, but regardless of the folder where you put your photos, if you want them someplace else, you use organizer to do it.

  • Help with opening Adobe Reader and downloading updates

    I can not open Adobe .pdf files any longer (this started yesterday, prior to that I could open adobe files).
    When I double click a .pdf file I get this notice on my screen: Windows cannot access the specified device path or file. You may not have the appropriate permission to access file.
    So I went to the Adobe download site to download a new copy of Adobe.  When I start the download I get this on the screen:  The instruction at "0x0e3a0068" referenced memory at "0x0e3a0068."  The memory could not be written.  Then two options are listed: click OK to terminate or cancel to debug.  So I click on cancel and I get this on my screen: Internet Explorer has closed this webpage to help protect your computer.   A malfunctioning or malicious addon has caused I.E. to close this webpage.
    I don't have AVG running, I do have avast but I've disabled it.  I ran Registry Mechanic and an I.E. erasure program but nothing helps.
    I have gone into I.E. and reduced the security level to its lowest state but no joy.
    So, any ideas or suggestions on what's the problem and how to overcome it would be appreciated.  Thanks, in advance, for your reply.  Jim R.

    Hi Mike..tried that as well but no joy.  A friend of mine was looking at it all and noticed that it was an I.E. thing as far as not letting me redownload the reader so I went to Mozilla Firefox and I could download a new version but....whenever I attempt to open a .pdf file I get that message, "Windows can not open the specified device, path or file. You man not have the appropriate permissions to access the item." 
    Damn...this is irritating as I need to get to some of thos files as I need them for a Journal I'm working on as editor-in-chief. 
    It all worked just fine last Saturday but starting Monday when I was on my flight out to D.C.  no joy. 
    Sigh...Jim R.
    Jim R.
    Date: Tue, 1 Dec 2009 14:50:27 -0700
    From: [email protected]
    To: [email protected]
    Subject: Help with opening Adobe Reader and downloading updates
    Under the help menu, there is an option to repair the installation of reader. Did you try that?
    >

  • Need help with JTextArea and Scrolling

    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import javax.swing.*;
    public class MORT_RETRY extends JFrame implements ActionListener
    private JPanel keypad;
    private JPanel buttons;
    private JTextField lcdLoanAmt;
    private JTextField lcdInterestRate;
    private JTextField lcdTerm;
    private JTextField lcdMonthlyPmt;
    private JTextArea displayArea;
    private JButton CalculateBtn;
    private JButton ClrBtn;
    private JButton CloseBtn;
    private JButton Amortize;
    private JScrollPane scroll;
    private DecimalFormat calcPattern = new DecimalFormat("$###,###.00");
    private String[] rateTerm = {"", "7years @ 5.35%", "15years @ 5.5%", "30years @ 5.75%"};
    private JComboBox rateTermList;
    double interest[] = {5.35, 5.5, 5.75};
    int term[] = {7, 15, 30};
    double balance, interestAmt, monthlyInterest, monthlyPayment, monPmtInt, monPmtPrin;
    int termInMonths, month, termLoop, monthLoop;
    public MORT_RETRY()
    Container pane = getContentPane();
    lcdLoanAmt = new JTextField();
    lcdMonthlyPmt = new JTextField();
    displayArea = new JTextArea();//DEFINE COMBOBOX AND SCROLL
    rateTermList = new JComboBox(rateTerm);
    scroll = new JScrollPane(displayArea);
    scroll.setSize(600,170);
    scroll.setLocation(150,270);//DEFINE BUTTONS
    CalculateBtn = new JButton("Calculate");
    ClrBtn = new JButton("Clear Fields");
    CloseBtn = new JButton("Close");
    Amortize = new JButton("Amortize");//DEFINE PANEL(S)
    keypad = new JPanel();
    buttons = new JPanel();//DEFINE KEYPAD PANEL LAYOUT
    keypad.setLayout(new GridLayout( 4, 2, 5, 5));//SET CONTROLS ON KEYPAD PANEL
    keypad.add(new JLabel("Loan Amount$ : "));
    keypad.add(lcdLoanAmt);
    keypad.add(new JLabel("Term of loan and Interest Rate: "));
    keypad.add(rateTermList);
    keypad.add(new JLabel("Monthly Payment : "));
    keypad.add(lcdMonthlyPmt);
    lcdMonthlyPmt.setEditable(false);
    keypad.add(new JLabel("Amortize Table:"));
    keypad.add(displayArea);
    displayArea.setEditable(false);//DEFINE BUTTONS PANEL LAYOUT
    buttons.setLayout(new GridLayout( 1, 3, 5, 5));//SET CONTROLS ON BUTTONS PANEL
    buttons.add(CalculateBtn);
    buttons.add(Amortize);
    buttons.add(ClrBtn);
    buttons.add(CloseBtn);//ADD ACTION LISTENER
    CalculateBtn.addActionListener(this);
    ClrBtn.addActionListener(this);
    CloseBtn.addActionListener(this);
    Amortize.addActionListener(this);
    rateTermList.addActionListener(this);//ADD PANELS
    pane.add(keypad, BorderLayout.NORTH);
    pane.add(buttons, BorderLayout.SOUTH);
    pane.add(scroll, BorderLayout.CENTER);
    addWindowListener( new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    public void actionPerformed(ActionEvent e)
    String arg = lcdLoanAmt.getText();
    int combined = Integer.parseInt(arg);
    if (e.getSource() == CalculateBtn)
    try
    JOptionPane.showMessageDialog(null, "Got try here", "Error", JOptionPane.ERROR_MESSAGE);
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Got here", "Error", JOptionPane.ERROR_MESSAGE);
    if ((e.getSource() == CalculateBtn) && (arg != null))
    try{
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 1))
    monthlyInterest = interest[0] / (12 * 100);
    termInMonths = term[0] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 2))
    monthlyInterest = interest[1] / (12 * 100);
    termInMonths = term[1] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 3))
    monthlyInterest = interest[2] / (12 * 100);
    termInMonths = term[2] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease Try Again", "Error", JOptionPane.ERROR_MESSAGE);
    }                    //IF STATEMENTS FOR AMORTIZATION
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 1))
    loopy(7, 5.35);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 2))
    loopy(15, 5.5);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 3))
    loopy(30, 5.75);
    if (e.getSource() == ClrBtn)
    rateTermList.setSelectedIndex(0);
    lcdLoanAmt.setText(null);
    lcdMonthlyPmt.setText(null);
    displayArea.setText(null);
    if (e.getSource() == CloseBtn)
    System.exit(0);
    private void loopy(int lTerm,double lInterest)
    double total, monthly, monthlyrate, monthint, monthprin, balance, lastint, paid;
    int amount, months, termloop, monthloop;
    String lcd2 = lcdLoanAmt.getText();
    amount = Integer.parseInt(lcd2);
    termloop = 1;
    paid = 0.00;
    monthlyrate = lInterest / (12 * 100);
    months = lTerm * 12;
    monthly = amount *(monthlyrate/(1-Math.pow(1+monthlyrate,-months)));
    total = months * monthly;
    balance = amount;
    while (termloop <= lTerm)
    displayArea.setCaretPosition(0);
    displayArea.append("\n");
    displayArea.append("Year " + termloop + " of " + lTerm + ": payments\n");
    displayArea.append("\n");
    displayArea.append("Month\tMonthly\tPrinciple\tInterest\tBalance\n");
    monthloop = 1;
    while (monthloop <= 12)
    monthint = balance * monthlyrate;
    monthprin = monthly - monthint;
    balance -= monthprin;
    paid += monthly;
    displayArea.setCaretPosition(0);
    displayArea.append(monthloop + "\t" + calcPattern.format(monthly) + "\t" + calcPattern.format(monthprin) + "\t");
    displayArea.append(calcPattern.format(monthint) + "\t" + calcPattern.format(balance) + "\n");
    monthloop ++;
    termloop ++;
    public static void main(String args[])
    MORT_RETRY f = new MORT_RETRY();
    f.setTitle("MORTGAGE PAYMENT CALCULATOR");
    f.setBounds(600, 600, 500, 500);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }need help with displaying the textarea correctly and the scroll bar please.
    Message was edited by:
    new2this2020

    What's the problem you're having ???
    PS.

Maybe you are looking for