maths

F

focode

when i divide 5/2 in java i get 2.0 how can i get the exact value
2.5 , actually i want to generate random number from 0 to 1 like .
00987 , .09654 ........ pls any one reply me soon
 
K

kapkan

focode пишет:
when i divide 5/2 in java i get 2.0 how can i get the exact value
2.5 , actually i want to generate random number from 0 to 1 like .
00987 , .09654 ........ pls any one reply me soon

int five = 5;
int two = 2;
double result = five/twoint two = 2; // result = 2

double result = (double)five/two // result = 2.5
 
L

lscharen

2.5 , actually i want to generate random number from 0 to 1 like .
00987 , .09654 ........  pls any one reply me soon

import java.util.Random;

Random rng = new Random();
double randomNumber = rng.nextDouble();

-Lucas
 
K

kapkan

focode пишет:
when i divide 5/2 in java i get 2.0 how can i get the exact value
2.5 , actually i want to generate random number from 0 to 1 like .
00987 , .09654 ........ pls any one reply me soon

int five = 5;
int two = 2;
double result = five/two // result = 2

double result = (double)five/two // result = 2.5
 
K

kapkan

focode пишет:
when i divide 5/2 in java i get 2.0 how can i get the exact value
2.5

int five = 5;
int two = 2;
double result = five/two // result = 2

double result = (double)five/two // result = 2.5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top