While (var! = Var)

while (var! = var) System.out.println ("loop ..");

fulfill it. how to declare..var

+3
source share
4 answers
public static void main(String[] args) {
    double var = Double.NaN;
    System.out.println("var : " + var);
    while (var != var) {
        System.out.println(" I am inside loop now! ");
    }

}
+15
source

Assuming this is homework, I will give you a hint, not an answer. You should define varas follows:

double var = // time for you to understand floating point

Edit: to make this answer more useful, here is a Wikipedia entry for special floating point values .

+21
source

double var = Double.NaN

+4

, , ; , [ ], , ; , , , :

public class Puzzle extends Thread {
static boolean keepRunning=true;
static int var=0;



public void run() {

while (keepRunning) {
        var++;
}   

}


public static void main(String[] args) {
    Puzzle p=new Puzzle();
    p.setPriority(Thread.MAX_PRIORITY);
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    p.start();
    System.out.println("Background Thread started");
    try { Thread.sleep(1000); } catch(Exception e) { ; } // Dirty hack to give the background thread chance to start :)
    while (var != var) {
        System.out.println(" I am inside loop now! ");
    }

    keepRunning=false; // we escaped from the loop, switch off the background thread.
}

}
0
source

Source: https://habr.com/ru/post/1728609/


All Articles