JAVA experts help...please - Sajha Mobile
SAJHA MOBILE
JAVA experts help...please
Posts 4 · Viewed 6724 · Go to Last Post
जय नेपाल
· Snapshot
Like · Likedby · 0
i need help with a code to find a random number between 1 to 70000 and use that number to convert to dollar and pennies amount.
result would be like this.  "You have $ 50.34".
im done with the random number generator but can't figure out how to combine two parts..
bange
· Snapshot
Like · Liked by · 0
int rand  = generateRandomNumbers(70000);
System.out.println("You have $ 50.34");

So simple...

Can you make the question clear?
sauravcn
· Snapshot
Like · Liked by · 0

import java.util.Random;
public class number{
public static void main(String [] args){
Random random =
new Random();
double number = random.nextInt(70000);
System.out.println (
"You have $" + number);
}

Last edited: 16-Feb-10 04:12 PM
Gajedi
· Snapshot
Like · Liked by · 0
Just changed saurvcn's code a little bit. 


import java.util.Random;
import java.text.DecimalFormat;
public class Randomnumber{
public static void main(String [] args){
Random random = new Random();
double number = random.nextInt(70000);
DecimalFormat df = new DecimalFormat("$ 0.00");
System.out.println ("You have " + df.format(number));
}
}

Use java random number generator wisely as it is not a reliable (in terms of cycle) random number generator.

Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 16 · Viewed 8957 · Likes 3
· Posts 8 · Viewed 5481 · Likes 3
· Posts 1 · Viewed 2688 · Likes 3
· Posts 1 · Viewed 2889 · Likes 3
· Posts 1 · Viewed 2529
· Posts 1 · Viewed 2534
· Posts 1 · Viewed 2691
· Posts 1 · Viewed 2794
· Posts 1 · Viewed 2601
· Posts 11 · Viewed 12655



Travel Partners
Travel House Nepal