Questions tagged [divide]

Separate or be separated into parts

Separate or be separated into parts

688 questions
-2
votes
3 answers

how do I subract ints from each other in an array Java

I have to write a program where the user inputs 3 numbers into an array and then the output is the numbers subtracted from each other. I have tried using a for loop for this but it just outputs the numbers added together then turns it negative eg :…
EmilyP
  • 67
  • 4
-2
votes
1 answer

Java dividing incorrectly

I am using Java 7 I am trying to get a double from dividing two integer: double chance = 1/main.getConfig().getInt("dailygiftItems.items."+key+".chance"); double w = Math.random(); System.out.println("Pulled:…
JarFile
  • 318
  • 2
  • 8
  • 30
-2
votes
2 answers

Calculation in Java

I have the following calculation in Java: rightMotor = (int) (((double)speed)/((double)100)*rightMotor)); Speed and rightMotor are both integers. The problem is, it keeps returning 0. I have tried to force to divide speed and 100 as doubles, which…
-2
votes
1 answer

Java: Ask user input and divide by those integers

In Java,I need to ask user input for two integers. The program needs to divide by these two integers and produce a decimal to the sixth place. I know that i will need to name two integers: numerator and denominator. Also, I need to name a double…
-2
votes
4 answers

Dividing a number into smaller random ints

So what i need is basically described in the subject. Like if i would put in number 12 and amount of parts it should devide into, i would like it to return something like (with 4 parts) 8, 2, 1, 1. But not doubles because i need the values as…
Guus
  • 399
  • 2
  • 15
-2
votes
3 answers

Sum up values in multidimensional php array

I try to figure out how to handle my array to do "some math" with its values. The array looks similar to this: Array ( [0] => Array ( [person1] => 71 [person2] => 49 [person3] => 15 ) [1] => Array ( …
Felix Bernhard
  • 396
  • 6
  • 24
-2
votes
1 answer

Java - What happens with this part of code?

I am currently watching some tutorials and I am stuck at a part that looks like this: int x = (int) a_float / an_int; What will happed if a_float / an_int; is not an integer? Will the number be rounded / floored / weird stuff?
user3029101
  • 317
  • 1
  • 3
  • 13
-2
votes
2 answers

java giving .9999999 instead of a rounded whole number

Here is the extracted code : long timeMs = 1473; double timeS = (timeMs / 1000) + (timeMs% 1000) / 1000.0; System.out.println(timeS); And the output is: 1.4729999999999999 So basically, I was just trying to convert the time taken in seconds into…
Topstar
  • 41
  • 5
-2
votes
3 answers

divide string in into equal parts

I can sum up strings: result=[firstString stringByAppendingString:secondString]; I can subtract one string from another: result=[firstString stringByReplacingOccurencesOfString:secondString withString:@""]; Can you help me to divide a string into…
nicael
  • 18,550
  • 13
  • 57
  • 90
-2
votes
2 answers

dividing an array into subarrays

I am trying to split the below array. array_chunk, splice, etc dint give me output as expected. Below is the input array: Array ( [0] => Stephen [1] => stephearce [2] => s@gmail.com [3] => Stephen [4] => stephon …
shablm
  • 15
  • 1
  • 6
-2
votes
2 answers

Float division being silly when saved in variable - but not when "used directly"

So my problem is that I am trying to position a sprite in the middle of the screen. How to do that is very simple but the calculations made during runtime are wrong. I have come to the conclusion that it is about floating points being messy in…
Simon
  • 470
  • 1
  • 7
  • 22
-2
votes
4 answers

Recursive function divide a number

I need to create a recursive function that receives a number by two without using /. This is what I wrote, but it works only if after dividing it will still be a decimal number and not a float, that's why I asked. int recursive(int a, int b){ if…
Boris
  • 65
  • 1
  • 1
  • 9
-2
votes
2 answers

Dividing a number and display a remainder in C#

Hi I am currently teaching myself C# using different books and online solutions, there is one exercise that i cant really get my head around. I had to divide a number by another number in C# using iteration and subtraction but the remainder had to…
user2311703
  • 23
  • 1
  • 6
-3
votes
1 answer

PHP Division isn't calculating property, help please

I have one variable ($TotalCountyTaxAmount) I want to divide by 365 to calculate a daily tax rate. In this example the variable value is 1614.21. When I divide the variable by the number of days (e.g. $TCA / $days), I get 0.2261 which is incorrect. …
-3
votes
1 answer

Divide integer in array and store it as double in array

for(int i = 0; i < iData; i++) { if(hPred[i]<=jData[i]) { akur[i] = hPred[i] / jData[i]; } else if(hPred[i]>jData[i]) { akur[i] = hPred[i] / jData[i]; akur[i] = akur[i] - 1.000; } } I got some issues…