Incorrect output for Min,Max, & Avg loops

This code is mostly working to compute the average and to get the maximum but it is taking 12 inputs and not 10 as required. I'm a bit unsure how to implement the Min into this as well. I would appreciate any guidance that can be provided on this as I'm stumped. Thank you.
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        int maxGrade = 0;
        int minGrade = 0;
       int total = 0;
       int testScores = 0;
       int grade = 0;       
        Scanner scan = new Scanner( System.in );
System.out.println ( "Please enter ten exam scores");
         for ( int i =1; i <= 10; i++ )
    testScores = scan.nextInt();
    total += testScores;
maxGrade = scan.nextInt();
grade = scan.nextInt();
if ( grade > maxGrade )
    maxGrade = grade;
System.out.println( "The average score is: " + ((double) (total) / 10));
System.out.println( "The Maximum score is: " + maxGrade);
}

Suggestions:
1) have your for loop go from 0 to i < 10. Since arrays are zero-based, this habit will help you in the future when you loop through arrays.
2) Your code indentation is atrocious making it hard for us (and for you!) to understand your code. Fix it and you'll make your future coding a lot easier.
3) Get the input only once in the for loop, and not outside and after the for loop as you are trying to to do here:
      maxGrade = scan.nextInt();
      grade = scan.nextInt();It makes no sense. Instead set the maxGrade and the minGrade both with the testScores entered the first time the for loop loops (when i equals 1 in your current code, but when i is 0 if you follow my recommendations). A simple if block -- if (i == 0) should work for this.
4) Inside the for loop and after testScores is entered, check if it is > max or < min and change max and min accordingly. Again this must be done inside of the loop. In pseudo-code
for i goes from 0 to less than 10:
   current score = get user input
   if i is 0
      set maximum score to current score
      set minimum score to current score
   end if
   if current score is less than minimum score
      change minimum score to current score
   end if
   if current score is greater than maximum score
      change maximum score to current score
   end if
end for loopLuck!
Edited by: Encephalopathic on Jul 10, 2010 7:43 AM

Similar Messages

  • Using sql functions (min, max, avg) on varray or table collection

    Hi,
    I would like to know if there is a way to use sql function or oracle sql function like Min,Max, Avg or percentile_cont on varray or table collection ?
    Does anyone encountered this type of problem ?
    Thanks

    Yes you can apply Min,Max, Avg... if varray or table collection type is SQL (created in the databaase) UDF, not PL/SQL declared type:
    SQL> set serveroutput on
    SQL> declare
      2      type str_tbl_type is table of varchar2(4000);
      3      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      4      max_val varchar2(4000);
      5  begin
      6      select max(column_value)
      7        into max_val
      8        from table(str_tbl);
      9      dbms_output.put_line('Max value is "' || max_val || '"');
    10  end;
    11  /
          from table(str_tbl);
    ERROR at line 8:
    ORA-06550: line 8, column 18:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 8, column 12:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    SQL> create or replace type str_tbl_type is table of varchar2(4000);
      2  /
    Type created.
    SQL> declare
      2      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      3      max_val varchar2(4000);
      4  begin
      5      select max(column_value)
      6        into max_val
      7        from table(str_tbl);
      8      dbms_output.put_line('Max value is "' || max_val || '"');
      9  end;
    10  /
    Max value is "ZZZ"
    PL/SQL procedure successfully completed.
    SQL> SY.

  • How to get min,max,avg time for query execution?

    Dear Friends,
    In AWR we are getting avg time taken to execute particular query, how can one get min,max time taken by query during number of executions.
    Thanks

    I would run the sql in a cursor for loop, to get a quite reasonable execution time without changing the actual execution plan:
    SQL> show user;
    USER is "HR"
    SQL> set timing on
    SQL> select count(*) from all_objects;
      COUNT(*)
         55565
    Elapsed: 00:00:03.91
    SQL> var p_sql varchar2(200)
    SQL> exec :p_sql := 'select * from all_objects'
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.53
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.75
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.73
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.66
    SQL> ---- alter system flush shared_pool;
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.80
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.64
    SQL>
    https://forums.oracle.com/thread/705536?start=15&tstart=0
    Regards
    Girish Sharma

  • MRP creating cancel notices for min max purchased items

    We use min max planning for many repetitive purchased items. These same items are also set to MPS/DRP Planned as well. This is only so we can use the Planned Order report to identify material shortages to flow schedules.
    However, MRP exceptions is requesting we cancel our min max purchased items since there is no demand. Can MRP be modified to NOT include min max planning method in cancel requests?
    If not, where can I find a tool to identify material shortages for flow schedules?

    Many thanks for this.
    I can see entirely why it's designed as such, but I just find it slightly frustrating that there's no way to break the link between the order and the shipment out to the depot. Just to clarify, we're not requiring the orders to change - they will still be made and will come in - but just that the orders themselves don't specifically need to be the stock that is used for the replenishment.
    So -
    1. Min Max identifies depot needs replenishing.
    2. Central distribution does not have (enough) stock to replenish.
    3. Order is made to replenish central distributions stock.
    4. We ship whatever we've got, when we've got it, to depot to replenish.
    It's the bit where Min-Max is trying to replensih a specific depot rather than our central distribution centre that's my problem.
    I suspect that, as you say, that specific issue is not directly fixable without getting our IT contractors to do a customisation.
    I'm going to look into your Supply Date Offset suggestion now, though I'm not sure how this affects the shipping after the orders are placed. The orders themselves are approved manually after we've checked our stock position (i.e. what's in with the recycling team), but we recycle & refurb probably 60% of our maint stock so there'll always be kit turning up after the order has been made because of the long lead times.
    Thanks again.

  • Incorrect outputs for grade program

    This is a secondary problem I am having to the first question I posted. The program runs but when I type in a letter grade this is my output regardless of the letter grade I put in:
    The score for the grade 'A' is 4.0
    Here is my code:
    #define_CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    voidmain()
    charGrade;
    printf("Enter a grade [A,B,C,D,F]");
    scanf("%c", &Grade);
    if(Grade ='A'||
    'a')
    printf(("The score for the grade 'A' is 4.0\n"));
    else
    if(Grade ='B'||
    'b')
    printf(("The score for the grade 'B' is 3.0\n"));
    else
    if(Grade ='C'||
    'c')
    printf(("The score for the grade 'C' is 2.0\n"));
    else
    if(Grade ='D'||
    'd')
    printf("The score for the grade 'D' is 1.0\n");
    else
    if(Grade ='F'||
    'f')
    printf(("The score for the grade 'F' is 0.0\n"));
    system("pause");

    On 3/20/2015 3:48 PM, leosucksatc wrote:
    if(Grade ='A'||'a')
    = is assignment. == is equality comparison. You had that right in your previous post.
    Also, the || operator doesn't work the way you think it does. Make it
    if (Grade == 'A' || Grade == 'a')
    Igor Tandetnik

  • Authorization for Min., Max level

    Dear Experts,
    Where to set authorization for Minimum and Maximum Inventory level for logistic users?
    Regards,
    Ravi

    Hi Ravi,
    Field level authorizations are not available in SAP.
    You can only set authorizzation based on Item Master data.
    Hope this will help.
    Thanks,
    Neetu

  • Vendor details for a Min Max requisitions

    Hi All
    When Min Max trigger some requisition interface lines, we need to get the vendor details also be populated,
    What set up it need to get these. Because when I run a Min-Max planning report, I am not getting the vendor details.
    What we have is we will be having a single item be with a single vendor and vendor site
    Please help.

    In the General planning tab for Sourcing type is it mentioned as Supplier?
    Is the use ASL flag in the Purchasing tab for the item enabled?
    The supplier and site details are active?
    The ASL for this item is still active ? (Check in the supplier line details in the ASL form)
    My funtional guy says yes to all the above quries.
    And also says All ASL have the sourcing rules assigned to the assignment set that is setup on the MRP: Default Sourcing Assignment Set profile, but this scenario is only for minmax
    So this issues is only for MIN-MAX.Please let me know if any thing to be done in setup to automatically get the
    vendor details into requistions lines of interface table based on items.
    Edited by: 834095 on Mar 14, 2011 2:59 AM

  • How to set physical min/max values for a scale in xy graph?

    Hello,
    I have troubles with the way LabView handles physical units in xy graphs. In particular, I use a time scale for the x axis.
    The values are timestamps and have the unit [s]. Now I want to read write the min max values for this scale via
    property nodes. It seems that the properties for min max do not support the use of the unit I use for the data for
    that same axis. This is very inconvenient and I am not even sure which kind of data to use at all for this properties.
    Is it simply converting to/from [s] using the unit converter?
    (I am using LabView 7.1 for the programm in question).
    Thanks,
    Olaf

    Hi Olaf
    "It seems that the properties for min max do not support the use of the unit I use for the data for that same axis."  
    What are the units you are using? can you make it a littlebit clear.
    You can change the units also using Property node.
    Just check the attachment once. If that is what you are looking for, then the problem is solved.
    Regards
    Anil
    Message Edited by reddy on 05-23-2006 05:25 AM
    Message Edited by reddy on 05-23-2006 05:27 AM
    Attachments:
    X-Scale.jpg ‏8 KB

  • Min max in itab

    i have itab with 10 rows of lbkum per matnr
    i need to take the min and max per matnr and put 1 line into new itab that have
    matnr
    stock
    min
    max PLSSSSSSSS

    Hi rani,
    1.  Input is :
    1-1
    1-2
    1-3
    2-11
    2-12
    2-33
    2. ouput is
    1 1 3
    2 11 33
    3. Just copy paste in new program
      (MTAB is the final internal table)
    4.
    report abc.
    data : begin of itab occurs 0,
           matnr like mara-matnr,
           lbkum type lbkum,
           end of itab.
    data : begin of mtab occurs 0,
           matnr like mara-matnr,
           minlbkum type lbkum,
           maxlbkum type lbkum,
           end of Mtab.
    data : tabix type sy-tabix.
    START-OF-SELECTION.
      ITAB-MATNR = '1'.
      ITAB-LBKUM = 1.
      APPEND ITAB.
      ITAB-MATNR = '1'.
      ITAB-LBKUM = 2.
      APPEND ITAB.
      ITAB-MATNR = '1'.
      ITAB-LBKUM = 3.
      APPEND ITAB.
      ITAB-MATNR = '2'.
      ITAB-LBKUM = 11.
      APPEND ITAB.
      ITAB-MATNR = '2'.
      ITAB-LBKUM = 12.
      APPEND ITAB.
      ITAB-MATNR = '2'.
      ITAB-LBKUM = 33.
      APPEND ITAB.
    First get all Distinct MATNR in MTAB
      loop at itab.
        mtab-matnr = itab-matnr.
        MTAB-MINLBKUM = '999999999'.
        MTAB-MAXLBKUM = 0.
        collect mtab.
      endloop.
    Then check for Min Max
      LOOP AT ITAB.
        read table mtab with key matnr = itab-matnr.
        if sy-subrc = 0.
          tabix = sy-tabix.
          if itab-lbkum < mtab-minlbkum.
            mtab-minlbkum = itab-lbkum.
          endif.
          if itab-lbkum > mtab-mAXlbkum.
            mtab-mAXlbkum = itab-lbkum.
          endif.
        MODIFY MTAB INDEX SY-TABIX.
        endif.
      ENDLOOP.
      break-point.
    regards,
    amit m.

  • Min Max Report - Eroneous Quantities in the Demand Quantity Column

    I have a min max report and I have eroneous quantities inthe demant quantity column. I would like to know where these quantities are coming from. I cannot find them anywhere in the system. There are not POs, requisitions, move orders or sales orders that can explain these quantities. It is causing issues the reorder quantity as well as the available quantity.

    Use Item supply /Demand form to match your calaculation for min max in addition to the setting that you have for min max .
    Reconsile the report with respect to the parameter that was used.
    tx,
    dr

  • Min-Max Planning concept

    Hi Neils,
    Can you please throw a light on --> Min-Max Planning Concept and what is the formula for Min-Max
    regds
    MRR

    Hi MRR,
    Min-max planning is used to maintain inventory levels for all of your items or selected items. With min-max planning, you specify minimum and maximum inventory levels for your items. When the inventory level for an item (on-hand quantities plus quantities on order) drops below the minimum, Oracle Inventory suggests a new purchase requisition, internal requisition, move order, or job to bring the balance back up to the maximum.
    See the Inventory Users Guide > Planning and Replenishment > Min-Max Planning for more detailed description of the principles behind. In addition to Min-Max you may want to consider Reorder Point Planning where you bring demand figures into the calculations.
    If you would like to have sales orders or production demands on end-item or sub-assembly levels influence the planning of components then a type of MRP is needed to break down a product structure to lower level material requirements. For even more advanced planning where capacities, constraints and may be even different optimizations objectives are to be considered you have to look at the Advanced Plannning Suite of applications.
    Hope this helps ypu in the right direction.
    /Niels LM

  • Min/max MRP and double star planned order

    Hi,
        What does setting up materials for min/max mean ? Is it just some concept r does it involve some specific settings in the material master ? I know there are minimum and maximum lot sizing procedures available. Are these to be taken into account to set materials up for min/max ?
    What does a planned order with two stars in the MD04 screen mean?
    Thanks

    Dear,
    Single *** means order is Firmed and **** means Capacity planning has been done for the  planned order.
    There is "storage location" MRP with min max levels.
    Have a look at the fields on the MRP screens in the material master and you will see the settings you can choose from.
    There should be no need for any config as long as your basic MRP config is there.
    The normal MRP run will then try to maintain the correct stock level in that storage location and you use the special procurement keys on the material master to determine where the stock should come from to replenish that storage location.
    Go to TcodeOMIA  here you will find min max for your plant.
    Regards,
    R.Brahmankar

  • Min max planning to get supply quantity

    hi
    in INV super user there is the standard report for MIN MAX planning report
    i see supply_qty but cant find the calculation on how supply_qty is done
    kindly guide me

    hi
    i cud only see ref to supply cut off date ,can u guide me on how the report displays supply qty ie from where is this calculation performed ,is there
    a query or a package for the same
    in the report i cud see all these values come from INV_MIN_MAX_TEMP ,this is a temporary table,how do values get in here?
    kindly guide me
    thanking in advance
    Edited by: makdutakdu on Feb 2, 2011 7:25 AM

  • Find MIN, MAX of multiple rows from multiple columns

    Hello,
    I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
    For Example: (C: Column, R: Row, N - NULL/Blank)
    C:____1____2____3____ 4____Max
    R:____20___22___13____4____*22*
    R:____N____N____32____14___*32*
    R:____N____12____N____N____*12*
    That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
    So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
    Here is my current code:
    CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END

    Hi Thank you for your feedback, unfortunately, I just found out that EVALUATE Function is disabled in our environment for security reasons, so the only other way I've discovered is this:
    The problem is that none of the conditions in the case statement are met--so the column is set to null. You can add a WHEN statement (section 2 below) to catch the nulls. There are five cases to consider:
    Case 1: begin insp > bad order
    Case 2: begin insp < bad order
    Case 3: bad order only (begin insp is NULL)
    Case 4: begin insp only (bad order is NULL)
    Case 5: both begin insp is NULL and bad order is NULL
    1) If bgn-crm-insp-ob > report-bo-ob then bgn-crm-insp-ob
    (Case 1)
    CASE WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob') > filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    2) If report-bo-ob is NULL then bgn-crm-insp-ob
    (Case 4, 5) for case 5, you will get NULL
    WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') IS NULL THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    3) Else report-bo-ob
    (Cases 2, 3)
    ELSE filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') END
    Hopefully this works, I'll give feedback if it does, or if you have any further suggestions please submit, again, THANK YOU SO MUCH ANYWAYS!

  • Min Max Vs Reorder Planning

    Hi All,
    What is the difference between both, Min Max & ReOrder Planning?
    Thanks

    Hi,
    Min-Max planning will be either maintained at Subinventory level or Organization level.
    If the onhand Qty falls below either minimum or Maximum level then system will generate either Purchase Requisitions or Work Orders in WIP module to replinish the inventory.
    On running the Min-Max report system will consider the existing Onhand,PO qty or the Sales Order demand as per the input parametres.
    Reorder Point is an alternate planning method for Min-Max planning method.
    This will replinish once the Item Onhand falls below {Safety Stock+(LeadtimeX Demand)}.This will also produce Purhcase Requisitions for replinishments.
    Thanks
    -Arif.

Maybe you are looking for

  • How do i know whether flash player is installed on client browser or not through code.

    I want to use Adobe flash player in my web page. But If the adobe flash plyer is not installed at client side, it won't work. So how do i Know if the adobe flash player is installed or not on client side on linux or windows machine through the code.

  • Can't put music into Podcast

    Ok. I'm new to this. Probably NOT doing something right. I'm creating a podcast and want to use a music bed. When I try to drag/drop an MP3 from iTunes into a new track, I get the message that the music file is being installed, but it doesn't show up

  • Music Downloading

    I have just received a new Nokia Lumia 520 for Christmas and yes, it is an amazing phone. The thing is, I can't transfer my music from my laptop to the phone. I had no problem downloading music onto it from my windows 7 computer. But today when I had

  • Iweb domain name

    Hi, When publishing a site with iWeb, I always get very long domain names like www.ostendbeach.be/OSTENDBEACH/index.html in my browser. Can I choose to only see www.ostendbeach.be with no other referrals to sub-folders in my browser ? Thanx, Jan

  • Novice to Flash coding and editing

    I have a pre-made template that was built by an earlier version of Flash.  I'm using Flash CS5 Pro, and when I preview the site, the page buttons across the top all say "Home", there are symbol layers for the buttons that are titled; b1, b2, b3, b4,