JAVA experts help...please

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

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..

जय नेपाल · Feb 16, 2010 1:02 PM · 11,521 views

3 Replies

int rand  = generateRandomNumbers(70000); System.out.println("You have $ 50.34"); So simple... Can you make the question clear?

bange · Feb 16, 2010 3:35 PM

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

SAURAVCN · Feb 16, 2010 3:59 PM

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.

Gajedi · Feb 16, 2010 5:16 PM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all