Define integer (int); What’s the default value?

In most cases, there is no “default” value for an int object. If you declare int i; as a (non-static) local variable inside of a function, it has an indeterminate value. It is uninitialized and you can’t use it until you write a valid value to it. It’s a good habit to get into to … Read more

Dividing two integers to a double in java

This line here d = w[L] /v[L]; takes place over several steps d = (int)w[L] / (int)v[L] d=(int)(w[L]/v[L]) //the integer result is calculated d=(double)(int)(w[L]/v[L]) //the integer result is cast to double In other words the precision is already gone before you cast to double, you need to cast to double first, so d = ((double)w[L]) … Read more

Is int? thread safe?

The question is poorly worded, and hence the confusion in the answers so far. The question should be “are reads and writes to a variable of type int? guaranteed to be atomic?” No, absolutely not. The spec is extremely clear on this point: Reads and writes of the following data types are atomic: bool, char, … Read more

Making an array of random ints

You are never assigning the values inside the test2 array. You have declared it but all the values will be 0. Here’s how you could assign a random integer in the specified interval for each element of the array: int Min = 0; int Max = 20; // this declares an integer array with 5 … Read more