# Data type conversion problem for leetcode pratice "Moving Average from Data Stream"

When I was running the code for the leetcode question ""Moving Average from Data Stream"". I got a partly different output with the expected: Here is my code: class MovingAverage { int front = 0, rear = 0; Double sum = 0.00000; int[] data; public MovingAverage(int size) { data = new int[size]; Arrays.fill(data, 0); }… Read More Data type conversion problem for leetcode pratice "Moving Average from Data Stream"

# Why does misusing 1 instead of 1.0 from an int exceeding limits effect the value we get when we convert it to a double

This is the code I will be using… public class foo { public static void main(String [] args){ int a = (int) Math.pow(2, 30); double d = (a + a – 1.0); double f = (a + a – 1); System.out.println(d); System.out.println(f); } } The outputs are -2.147483649E9 and 2.147483647E9. I do not understand why… Read More Why does misusing 1 instead of 1.0 from an int exceeding limits effect the value we get when we convert it to a double

# math.sqrt gives me incorrect result (double)

I am writing a program that prints 100 random coordinates within a circle. The circle has the radius 10 and its center is located at (0,0). However, some of the coordinates y:value is incorrectly calculated when I’m using: y = Math.sqrt(100 -x^2) The result is like off… Why is that ? (See picture) For positive… Read More math.sqrt gives me incorrect result (double)

# Why does my deposit feature only let me deposit 10,000 or less?

I created a bank app, and when I try to deposit money that is over 10,000, my error message that I set up displays, but any number under works.. I assume this has something to do with value types. I used int, however I tried double but can’t figure that out too. /* FUNCTION DEFINITION… Read More Why does my deposit feature only let me deposit 10,000 or less?

# Using a final double variable in java

I’m making a small program that asks the user for the radius of a circle and then outputs the radius, diameter, area, and circumference of the circle in java. I was asked to use a final double to declare the number pi, and I need to use that later in the code to calculate values.… Read More Using a final double variable in java

# how to fix double in flutter even if the last decimal is 0

Hi so i have a double seems like this d1 = 12.106 and i need to show in to a string ‘12.130’ double num1 = double. parse((12.3404). toStringAsFixed(3)); well i expected to return "12.130" but it returned "12.13" the thing i need a string "12.130" instead "12.13" double num1 = double. parse((12.3404). toStringAsFixed(4)); so tried… Read More how to fix double in flutter even if the last decimal is 0

# Positive input exceeds the limit of integer – dart

I have this function to convert hex to double. The values are some coordinates so the latitude should be a positive number and longitude a negative one. Something like this: 41.43757591162915, -8.418569400003188 For the Latitude works fine, but returns the error when trying to convert the Longitude. Expected value: -8.418569400003188 converting from C020D67F4DBDF8F5 I read… Read More Positive input exceeds the limit of integer – dart

# Why double becomes int?

When I run this code, I get output "System.Double, 3" namespace NewApp { class Program { static void Main(string[] args) { double a = 1.0; double b = 2.7; a = Math.Round(b); Console.WriteLine(a.GetType() + ", " + a); } } } Why I see "3", if a is double variable and I supposed to see… Read More Why double becomes int?

# Should we add "d", "f", etc. at the end of double, float values in Java?

I am generally confused when defining double and float variables and as far as I know, it is good practice to add "d", "f", etc. at the end of double, float values. However, as the IDE does not warn me, generally I omit them and think it would also be ok and no need to… Read More Should we add "d", "f", etc. at the end of double, float values in Java?

# set MySqlParameter = -1 if null

I am trying to use SQL queries, but I meet a problem with nullable objects : Here is my code where I define all MySql parameters : MySqlParameter[] listParams = new MySqlParameter[] { new MySqlParameter("id", this.ID), new MySqlParameter("idStock", this.idStock), new MySqlParameter("certificate", this.certificate), new MySqlParameter("idLO", this.launchingOrder.ID), new MySqlParameter("idToleOri", this.toleOri.ID), new MySqlParameter("idTolesOri", string.Join("+", this.idTolesOri)), new MySqlParameter("listInstructions", string.Join("|",… Read More set MySqlParameter = -1 if null