Help Displaying Highest and Lowest Numbers

Hello everyone, I'm new to Java and I have an issue with my program.
All it does is randomly select 5 numbers from 1-10 right now, but I want it to display to the user the highest and lowest number that was selected. I'm not entirely sure how to do this so if you could help me that would be great. Here is my program.
import java.util.Random;
     public class Dice
          public static void main(String[] args)
               Random generator = new Random();
               int num1;
               int num2;
               int num3;
               int num4;
               int num5;
               int lowestnumber;
               int highestnumber;
               System.out.println("Let's roll the 10 sided dice!");
               num1 = generator.nextInt(11);
               System.out.println("Roll #1: " + num1);
               num2 = generator.nextInt(11);
               System.out.println("Roll #2: " + num2);
               num3 = generator.nextInt(11);
               System.out.println("Roll #3: " + num3);
               num4 = generator.nextInt(11);
               System.out.println("Roll #4: " + num4);
               num5 = generator.nextInt(11);
               System.out.println("Roll #5: " + num5);
//This is where my problem is, I'm not sure how to go about getting my two integers to read the highest
//and lowest number.
               System.out.println("The highest number you rolled was: " + highestnumber);
               System.out.println("The lowest number you rolled was : " + lowestnumber);
}

gmiller4th wrote:
Hello everyone, I'm new to Java and I have an issue with my program.
All it does is randomly select 5 numbers from 1-10 right now, but I want it to display to the user the highest and lowest number that was selected. I'm not entirely sure how to do this so if you could help me that would be great. Here is my program.
import java.util.Random;
     public class Dice
          public static void main(String[] args)
               Random generator = new Random();
               int num1;
               int num2;
               int num3;
               int num4;
               int num5;
               int lowestnumber;
               int highestnumber;
               System.out.println("Let's roll the 10 sided dice!");
               num1 = generator.nextInt(11);
               System.out.println("Roll #1: " + num1);
               num2 = generator.nextInt(11);
               System.out.println("Roll #2: " + num2);
               num3 = generator.nextInt(11);
               System.out.println("Roll #3: " + num3);
               num4 = generator.nextInt(11);
               System.out.println("Roll #4: " + num4);
               num5 = generator.nextInt(11);
               System.out.println("Roll #5: " + num5);
//This is where my problem is, I'm not sure how to go about getting my two integers to read the highest
//and lowest number.
               System.out.println("The highest number you rolled was: " + highestnumber);
               System.out.println("The lowest number you rolled was : " + lowestnumber);
}Instead of having a bunch of separate ints, you could just have one array and use an insertion sorting algorithm...
http://en.wikipedia.org/wiki/Insertion_sort
So instead, you would have:
import java.util.Random;
public class Dice
public static void main(String[] args)
Random generator = new Random();
int[] nums;
int lowestnumber;
int highestnumber;
System.out.println("Let's roll the 10 sided dice!");
nums[0] = generator.nextInt(11);
System.out.println("Roll #1: " + nums[0]);
nums[1] = generator.nextInt(11);
System.out.println("Roll #2: " + nums[1]);
nums[2] = generator.nextInt(11);
System.out.println("Roll #3: " + nums[2]);
nums[3] = generator.nextInt(11);
System.out.println("Roll #4: " + nums[3]);
nums[4] = generator.nextInt(11);
System.out.println("Roll #5: " + nums[4]);
nums = InsertionSorting(nums);
//The sorting method will sort the number from lowest to highest, thus:
highestnumber = nums[4];
lowestnumber = nums[0];
System.out.println("The highest number you rolled was: " + highestnumber);
System.out.println("The lowest number you rolled was : " + lowestnumber);
public static int[] InsertionSorting (int[] a) {
          for (int i = 1; i < a.length; i++ )
              int value = a;          // next item to be inserted in order
          int j;
          // Back up in the array to find the spot for value.
          for ( j = i - 1; j >= 0 && a[j] > value; j-- )
     // This element is bigger than the element being inserted,
     // so move it up one slot.
     a[j+1] = a[j];
     // a[j] is the item that should precede value.
          // Put value after it.
     a[j+1] = value;
          return a;
The comments in the insertion sort are not my own... I yoinked it from the web.
I apologize if there are any errors. Hope it helps
Edit: __colin  has a good suggestion... you'd want to use something like that as well for error protection.
Silly me, I just realized that my sorting is way more complicated than it needs to be... But it's fun anyway! -slightly embarassed-
Edited by: Thok on Oct 11, 2007 9:42 AM
Edited by: Thok on Oct 11, 2007 9:48 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Query displaying diffrence between highest and lowest salarys?

    I need to write a query that will display the difference between the highest and lowest salaries. Label the column DIFFERENCE.
    It should look something like so. I have no idea what to type in SQL plus to get this.
         DIFFERENCE
    4200

    Sweetness, thanks for this help, I just also started at this company called avid technologies
    www.avid.com and I Just learned SAP.
    Heres another problem if you can help:
    Create a matrix query to display the job, the salary for that job based on department number, and the total salary for that job for all departments, giving each column an appropriate heading
    and again the formatting is messed up.
         Job               Dept 10 Dept 20      Dept 30     Total
         ANALYST     6000                    6000
         CLERK          1300     1900          950     4150
         MANAGER     2450     2975     2850     8275
         PRESIDENT     5000                    5000
         SALESMAN                    5600     5600

  • Need help in query to display lot and serial numbers for a Wip Job Component

    Hi ALL,
    I have a requirement as below.
    I need to display lot and serial numbers for a Wip Job Component, i have a xml report in that for each wip job component i need to check whether it is a lot control item or serial control item based on that i need to display some data. so can you please help me to get the query to indentify the lot and serial number for a wip job component.
    Thanks

    Thank you for replying Gordon.  I did not remember I had asked this before.  I no longer have access to the other account. 
    What I need on the query is that I want  a list of items with the on order quantity and when we are expecting this order to be received.  The receiving date is based on the PO delivery date.  The trick here is that  I need to Master sku to show the delivery date of the component sku.  In my scenario all components have the same delivery date for the Master sku.  If there are mulitple delivery dates because each warehouse is getting them on a different date then I want to get the delivery date for that warehouse.
    Let me know if this is possible and if yes please guide towards a query for it.
    Thank you.

  • How to Find the highest and lowest cell in a column and figure the difference

    What I am tryng to do is have numbers find the high and low in Cloumn B and and put the difference in B6. So I would need it to Figure out that B3 is the highest and B2 is the lowest and give me the difference of .25 in B6

    Don,
    Begin by making Row 6 a Footer Row. You will find that option in the row tab menu that appears when you hover over the 6 tab and click the triangle.
    Then enter this formula in B6:
    =MAX(B)-MIN(B)
    Regards,
    Jerry

  • Displaying Row and Column Numbers

    I see through other research on Oracle SQL Developer that I should be able to display the row and column numbers on version 1.5.4, but I don't see where to go to turn this on. Suggestions?

    Suggestions?Ask in the SQL Developer forum?

  • How do yo highlight highest and lowest values

    I Excel you can use conditional formatting to highlight the lowest or highest number in a row or column.
    As a new user of iWorks I was wondering if this can be done with the conditional formatting feature within Numbers?

    Not directly. The conditional formatting doesn't allow any types of formulas, only comparisons to specific cells. Create a cell somewhere that uses the MAX or MIN function to determine the highest/lowest number in your column or row. Then your conditional format will be "if equal to" that cell.

  • Help Displaying Parent and child relationship on one page

    Hello,
    I have 2 tables, lets say Parent and Child, that I want to display both tables on the same page. Basically I'm looking at trying to split the page in half, the top being the Parent table and the bottom being the Child table. When the user selects a parent, I want the Child table to display that parent's child/children. I don't know if this is possible though JDeveloper but I would appreciate all the help I can get
    Thanks,
    Matt

    This is a trivial master detail task for ADF.
    Basically, in the data control palette - stand on the child node that is inside the parent node - drag it over to your page and drop it as a master detail - this will get you what you want.
    More information is in the ADF Tutorial:
    http://www.oracle.com/technology/obe/ADFBC_tutorial_1013/10131/index.htm

  • I'm new to Mac and the program/all called Numbers. I'm trying to use both Average and small in the same formula. What's I'm trying to do is take 20 cells, find the 10 lowest numbers, then get the average and after that multiply it by .96

    I'm new to Mac and the program/all called Numbers. I'm trying to use both Average and small in the same formula. What's I'm trying to do is take 20 cells in a column,  find the 10 lowest numbers, then get the average and after that multiply it by .96  I used to use Excel and the formula worked fine in that. Here is my Formula
    =(average(small(H201:H220,{1,2,3,4,5,6,7,8,9,10})))*.96
    This formula worked in Excel and when I converted my spreadsheet over to Numbers, this formula no longer works.
    The best that I have been able to do so far is use small in 10 different cells, then get the average of the 10 cells and finally multiply that average by .96  So instead of using 1 cell, I'm using 12 cells to get my answer.
    This is a formula that I will be using all the time. The next cell would be =(average(small(H202:H221,{1,2,3,4,5,6,7,8,9,10})))*.96
    Hoping I explain myself well enough and that someone can help me.
    Thanks

    You can still do it in one cell but it will be more unruly than the Excel array formula.
    =average(small(H201:H220,1),small(H201:H220,2),small(H201:H220,3),...,small(H201:H220,10))*0.96
    where you would, of course, replace the "..." with the remaining six SMALL functions.

  • 10.8.2   Mac Pro 2009   4 Apple Monitors = doesn't keep the display order and configuration. Please Help me!!

    Guys i have a Mac Pro 2009 with 4 monitors attached.
    Since i upgrade to 10.8, then to 10.8.1 and now to 10.8.2 my Mac Pro every time it starts, cannot remember the order and appearance of my displays so ihave to reorder them every single time.
    Can somebody tell me what to do???
    Please help me either wise i ma going to burn it!

    I have brand new 10.8.2 Mac Tower with two matching video cards ordered from Apple directly and have the same problem. It wont save the display settings and also cant seem to tell which video card is which either.
    In addition, the screen display images if loaded from a personal folder, is also not remembered after startup.
    Please advise us what to do, Apple!!!! This is urgent for me. I am proifessional user and this machine is for use on live projection shows. We put a ton of money into this machine and it can't even remeber the displays! Not very amusing.

  • Need Help in installations and connecting displays. Please!

    Hello Everyone,
    Need Help in installations and connecting displays. Please!
    Im planning on installing in a cafe shop : (Store Self improvement)
    4 TV's (can be  Built in Wi-Fi) Store menus
    2 touch screen tablets.  To be use as Emenu (digital Menu)
    1 60' TV ( Built in Wi-Fi) as Entrainment displays and in store advertising
    What do I need to organize my project and make it looks cool and how to manageand controll all of the displays TV.

    TNSTAAFL
    I DO NOT work for Best Buy, Geek Squad and any way affiliated with them. I am a self-employed repairman. I specialize in TV's and desktop computers. I do not take sides. If BB is wrong I will say so. If you are a moron with a false sense of entitlement, then I will tell you.

  • I am unable to retrieve spreadsheets.  Numbers displays the "Welcome To Numbers" page but does not allow saved spreadsheets to be opened.  It offers the "Open Recent" choice and displays saved file names but does not allow these files to be accessed.

    I recently upgraded to Numbers 3.5.2.  I have an older Macbook Pro (2009) and I run Yosemite 10.10.2.  I am unable to open any saved files that were created with earlier versions of Numbers.  When I open the Numbers app, I am offered the Welcome To Numbers page.  When I choose the 'Open Recent' option, I am offered the greyed names of files that I had recently used, however, I am unable to open any of these files (no error message is displayed).  Welcome To Numbers stays on the screen.  I tried opening the app by clicking on the file name but it produced the same results.  I am having a similar problem with Pages.   I suspect a compatibility problem between the new OSX and the new iWork offerings.   Has anyone else encountered this problem?  Does it require a setting change or is it a bug?

    I managed to download and install the iWork '09 apps.  However, when I attempt to open the app, I receive this error message:
    Numbers cannot be opened because of a problem.
    Check with the developer to make sure Numbers works with this version of OS X.  You may need to reinstall the application.  Be sure to install any available updates for the application and OS X.
    Problem Details and Configuration:
    Process:          Numbers [39838]
    Path:               /Applications/iWork '09/Numbers.app/Contents/Mac OS/Numbers
    Identifier:          com.apple.iWork.Numbers
    Version          ???
    Build Info:     Numbers-2990000~12
    Code Type:     X86 (Native)
    Parent Process:  ??? [1]
    Responsible:     Numbers [39838]
    User ID:          501
    Any thoughts as to what has to happen next?  I am running the latest OS X available (Yosemite 10.10.2)

  • I am unable to clear my recent call list. Both the 'missed' and 'all' numbers appear even after deleting. It was happening on ios 7.0.4 and is present on 7.0.5. Any help.

    I am unable to clear my recent call list. Both the 'missed' and 'all' numbers appear even after deleting. It was happening on ios 7.0.4 and is present on 7.0.5. Any help.

    No.
    You got 2 more basic troubleshooting steps left before you make an appointment with the Apple genius bar for an evaluation:
    Restore from backup
    Restore as new
    http://support.apple.com/kb/HT1414

  • Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    I have friends all over Europe, does it matter what number they use to call me? Nope! All incoming calls are free for me.
    The only time you ever have to worry about which number is if you get charged for incoming domestic/international calls.
    You can tag their number (work/home/iphone) and that may show on the CallerID accordingly.
    It should show, John Doe
    underneath,    work/home/mobile
    For example:
    http://shawnblanc.net/images/img-0009-1.png

  • Second highest and third lowest value in columns

    create table test (id number,a number,b number,c number,d number,e number);
    insert into test values (1,13,8,7,14,15);
    Required output with column names 2nd highest and 3rd Lowest Value
    ID           2NDHIGHEST        3RDLOWEST
    1            14[D]             13[A]Thanks.

    So because you didn't quite get the answer you wanted before you thought you'd just ask the same question again?
    That just confuses people as they don't know what solutions you've already been provided with.
    So what you want is something like...
    SQL> ed
    Wrote file afiedt.buf
      1  with test as (
      2                select 1 as id,20 as a,23 as b,38 as c,15 as d, 13 as e from dual union all
      3                select 2, 0, 18, 18.1, 19, 7 from dual union all
      4                select 3,40,-2,25.67,28,17 from dual union all
      5                select 4,13,8,7,14,15 from dual
      6               )
      7  --
      8  -- end of test data
      9  --
    10  select id
    11         -- take the results and pivot them back to single rows
    12        ,max(case when rnk = cnt_rnk-1 then to_char(n)||' ['||l||']' else null end) as second_highest
    13        ,max(case when rnk = 3 then to_char(n)||' ['||l||']' else null end) as third_lowest
    14  from (-- determine the maximum rank value within each id group
    15        select id, l, n, rnk
    16              ,max(rnk) over (partition by id) as cnt_rnk
    17        from (-- determine ranks for the 'n' values within each id group
    18              select id, l, n
    19                    ,dense_rank() over (partition by id order by n) as rnk
    20              from (-- unpivot the data to make the structure workable
    21                    select id
    22                          ,decode(rn,1,'a',2,'b',3,'c',4,'d',5,'e') as l
    23                          ,decode(rn,1,a,2,b,3,c,4,d,5,e) as n
    24                    from test
    25                         cross join (select rownum rn from dual connect by rownum <= 5)
    26                   )
    27             )
    28       )
    29  where rnk = 3
    30  or    rnk = cnt_rnk-1
    31  group by id
    32* order by id
    SQL> /
            ID SECOND_HIGHEST                               THIRD_LOWEST
             1 23 20 [a]
    2 18.1 [c] 18 [b]
    3 28 [d] 25.67 [c]
    4 14 [d] 13 [a]

  • I have a itune gift card  and the numbers on the back  came off . i have the store receit  but the store can not help me

    i have i tune gift card and the numbers on the back are gone i have the store receit but thay can not help

    Try contacting Apple through their Express Lane.
    Just click iTunes on the left > iTunes Store > iTunes Cards and Codes, and then fill out the form to see if they can take care of the problem.

Maybe you are looking for