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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I'm New To Java and I'm Confused about Math.min

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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.
    Last edited by Norm; March 23rd, 2021 at 06:59 AM. Reason: Fixed code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    kept reading about math.min and I'm still confused now
    Can you copy and paste here the part you are confused about with an explanation of your confusion?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Very Confused Over Java Problem
    By Loremaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 30th, 2017, 06:20 AM
  2. java question confused on:
    By rickster31 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2012, 09:06 AM
  3. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  4. Newbie: seem confused with Java
    By boyscout in forum Java Theory & Questions
    Replies: 1
    Last Post: April 8th, 2011, 09:12 AM
  5. [SOLVED] Java beginner is confused....
    By truebluecougarman in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 27th, 2011, 08:50 AM

Tags for this Thread