Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

I'm a Beginner Programmer in Java trying to use Math.random

$
0
0
Hi everyone,
Im having issues with my java program, which im suppose to use Math.random.

My task is that I have 80 cats and dogs together and I'm suppose to use Math.random to get a random amounts for the number of cats and random number for dogs. I was able to create my scale to be 80, so my numbers for either cats or dogs dont become higher than that, but i cant figure out HOW TO MAKE THOSE RANDOM NUMBERS OF EACH CAT AND DOG TO EQUAL 80. If you can please take the time to help me figure this out, it would be greatly appreciated. I've been spending 3 hours trying random stuff to solve this problem, but theres no success. I wont even be done after that, I have to do a bunch of if and else statements, but i cant get to that till I figure out to get my random numbers to equal to 80. HERES WHAT I HAVE TO FAR :) Thanks in Advance!

[Code]

public class Assembly
{
public static void main (String[]args)
{
int scale = 80;

int cats = (int)(scale * Math.random()+1);
int dogs = (int)(scale * Math.random()+1);

System.out.println(cats + " Cats ");
System.out.println(dogs + " Dogs ");

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>