Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a random int
#1
Hello I've got this code, and I hope you can help me out a little bit.
[code2=java]import java.util.Random;
public class objectIntro {

public static void main(String[] args)
{
String a = "blabla";
String b = "lala";
Random weight = new Random();
//Random rnd = new Random();
//System.out.println("The weight is: " + rnd.weight(100));
if(weight <= 55)
{
System.out.println(b + "is slimmer then: "+ a);
}else if(weight >= 80)
{
System.out.println(a + " is fatter then: "+ b);
}

}

}[/code2]

So what does not work?
I want to make the weight int. random and later it can show who is fatter/smaller.
Like the output:

The weight it: (random generated) 83
blabla is fatter then lala

please help me.

GRTZ,
- mustafa6155
#2
[code2=java]public static int randInt(int min, int max) {

// Usually this can be a field rather than a method variable
Random rand = new Random();

// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = rand.nextInt((max - min) + 1) + min;

return randomNum;
}[/code2]

Source from http://stackoverflow.com/questions/36368...-with-java


Forum Jump:


Users browsing this thread: 1 Guest(s)