Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to code an algorithm to implement Gamma Correction but I am unable todo so with below code, because of a high power base. Wondering if anyone could fix below code to raise color values between 0,1 Thanks
The problem is in your math.
int / int will cause a truncation.
If red = 9 and you execute 9 / 255 the result is 0.
Try making all your literal values floating point
(for example 255.0 instead of 255).
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 days ago.
Improve this question
I am facing issues while attempting a task that involves converting 0s (avaible seat) to the letter "O" and 1s (occupied seat) to the letter "X" in 2-dimensional arrays of strings. I have three rows of varying lengths (12, 16, and 20) that are filled with 0s, but I can't seem to get the output to look like the following:
How it should print like
I have tried to understand by watching videos and reading documentation, but I am still unclear. Can someone please help?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
for a project of mine i need to detect the current incoming megabytes per second on linux coded in python.
i found someone elses code that does the correct thing but its coded in java and i dont exactly understand it. any pointers?
TOTAL_INCOMING_BYTES_FILE = "/sys/class/net/%s/statistics/rx_bytes",
final double current_mbps =
((current_total_bytes - Long.parseLong(Files.readAllLines(Paths.get(new File(String.format(TOTAL_INCOMING_BYTES_FILE, ETH_INTERFACE)).toURI())).get(0))) / 125000) * (-1);
i found someone elses code that does the correct thing but its coded in java and i dont exactly understand it.
Indeed Long.parseLong(Files.readAllLines(Paths.get(new File(String.format(TOTAL_INCOMING_BYTES_FILE, ETH_INTERFACE)).toURI())).get(0)) is an incredibly convoluted way to read a number from a file, and to take the abstruseness a bit further the fraction of a difference is multiplied by −1 instead of exchanging the subtrahend and the minuend.
With the constant 125000 the expression computes the current_mbps if current_total_bytes has been fetched one eighth of a second ago (since 125000 is one eighth of a million). The (re-)initialization of current_total_bytes is missing from the code.
Here's a Python snippet for the computation of e. g. the eth0 rate:
import time
earlier_total_bytes = None
while 0 <= (current_total_bytes := int(open("/sys/class/net/eth0/statistics/rx_bytes").read())) \
and earlier_total_bytes is None: earlier_total_bytes = current_total_bytes; time.sleep(.125)
current_mbps = (current_total_bytes - earlier_total_bytes) / 125000
Of course this can be adapted for other sampling intervals, also repeated and variable.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have list values in stream while iterating I need to check if that value is negative or not if negative return zero or else retrun same value
Below is my code
{
Inventory .stream().
map.(inventory.value).sum;
}
You can just use Math.min for this. You'll have to map over them as integers, presumably:
Inventory.stream()
.mapToInt(it -> Math.min(0, it.value))
.sum()
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My sqlserver table has a column designed as a BIT datatype. It has values 1 and 0s
Then in my Java code, I do
result = new ArrayList
result.add( (Boolean)(rs.getBoolean("columnName")));
Then when I read the value from the list - it shows as Long.
According to everything I find, it says hat a BIT datatype is supposed to map to boolean.
Why does it come as Long?
What can be done to fix this?
You can call getBoolean directly and let it take care of all the casting/coverting:
result.add(rs.getBoolean("columnName"));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Is there a method to round a double the nearest of two doubles?
e.g.:
I want to round numbers to the nearest between 3.3 and 3.7.. so:
3.4 --> 3.3
3.472 --> 3.3
3.5 --> 3.7
3.573 --> 3.7
And so on...
Is there a method to do that?
As far as I know, there is no such method. However, writing your own shouldn't present a great difficulty:
static double nearest(double val, double left, double right) {
return Math.abs(val-left) <= Math.abs(val-right) ? left : right;
}