Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## I'm New To Java and I'm Confused about Math.min

I need help so i was doing some random generation numbers for our class
I needed to generate 3 random numbers but then it said i need to use math.min process and make the 3 numbers output in ascending order
And i can't seem to i kept reading about math.min and I'm still confused now
Btw here's the code but it's just for the random num generation

```import java.util.*;
import java.lang.Math;

class GenNumber{

public static void main(String[] args) {

double Lowest,Mid,Max;
double x=0, y=0, z=0;
int num;
Random rnum = new Random();

System.out.println("Random Numbers:");
System.out.println("***************");

for (num = 1; num <= 3; num++) {
System.out.println(rnum.nextInt(100));
{
if(num == 1) x = rnum.nextInt(100);
}{
if(num == 2) y = rnum.nextInt(100);
}{
if(num == 3) z = rnum.nextInt(100);
}
}
Lowest = Math.min(x,y);
Lowest = Math.min(Lowest, z);

Mid = Math.max(Lowest, x);
Mid = Math.max(Mid, y);
Mid = Math.max(Mid,z);

Max = Math.max(x, y);
Max = Math.max(Max, z);
System.out.println("sorted random numbers:"+x, y, z);
}
}```

I also tried storing them through x y and z but i still have no luck figuring it out.

2. ## Re: I'm New To Java and I'm Confused about Math.min

Can you copy and paste here the part you are confused about with an explanation of your confusion?

[code]
[/code]

to get highlighting and preserve formatting.

3. ## Re: I'm New To Java and I'm Confused about Math.min

I edited the post.
Kind sir i am confused about sorting the numbers using math.min at first i successfully sorted them in ascending order but what I'm asked to do is print
The 3 random generated numbers and print the ascending sort afterwards and my code always only prints the sorted one not the original. Very much thanks for helps I'm sorry if this is such a newbie problem but I'm also new to forums this is my first time

4. ## Re: I'm New To Java and I'm Confused about Math.min

what I'm asked to do is print
Please copy the program's current output and paste it here.
Then change that to show what the desired output should be.
For example:
current output
4 2 1
desired output
1 2 4

I edited the post.
Please fix the indentations of the statements. Logically nested statements should be indented. Too many of the statements in the posted code start in the first column.
The first part of the code is good; the last part needs to be fixed.

There is no need for a for loop to get the 3 numbers. Just have three assignment statements, one for each variable.