Originally Posted by
Achtung
...
int ranominteger2 =1 + (int)(Math.random()*9);
i need to know is that right ...
It's always OK to ask, but why not get into a mode of cranking out little test programs to verify your understanding of things like this? Might be faster than posting a request and waiting for a helpful response. And getting the extra practice of writing quickies like this can't possibly be bad, can it?
public class Z {
public static void main(String [] args) {
int xmax = 0; // Start it off very small
int xmin = Integer.MAX_VALUE; // Start it off very large
int num = 10000; // You don't really need this many, but...
for (int i = 0; i < num; i++) {
int x = (int)(Math.random() * 9) + 1;
if (x > xmax) {
xmax = x;
}
if (x < xmin) {
xmin = x;
}
}
System.out.println("For " + num + " random deviates: " +
"xmin = " + xmin +
", xmax = " + xmax);
} // End main()
} // End class definition
Output:
For 10000 random deviates: xmin = 1, xmax = 9