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 21 of 21

Thread: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

  1. #1
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Question Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Hello,
    I am a newbie to Java and I am having troubles with my code. It does not calculate the maximum, minimum or average of the 10 numbers that the user is prompted to input. So I turn to the ones who know Java and programming, you. I know this may seem like a stupid question, but I hope you can give me some insight to where my problem lies. Thank you, any help is deeply appreciated.

    My code:
    import java.util.Scanner;

    public class moretest
    {
    public static void main( String [ ] args )
    {
    int total = 0;
    int number;
    int minGrade = 101;
    int maxGrade = 0;
    float average;

    Scanner scan = new Scanner( System.in);

    for ( int i = 0; i < 1; i++ ) //Executes 1 time
    {
    System.out.println("Enter ten scores between 0 and a 100");

    for ( int n = 0; n < 10; n++ ) //Executes 10
    {
    System.out.println("Score: ");
    number = scan.nextInt ( );

    if (number > maxGrade)
    {
    maxGrade = number;
    }

    if ( number < minGrade )
    {
    minGrade = number;
    }

    if (number > -1 && number < 101)
    {
    total = total + number;
    }

    else{
    System.out.println("Input values are not acceptable, try again."); //The message displayed when number is out of range
    }
    average = total/10; //to calculate the average
    }
    }
    }
    }

    --- I hope I posted under the right sub-post..


  2. #2
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    111
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    code tags

  3. The Following User Says Thank You to llowe29 For This Useful Post:

    Knowledge_Feeds_The_Mind (February 26th, 2014)

  4. #3
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Please edit your code into proper highlights
    [c o d e = j a v a]
    // your code goes here
    [/ c o d e]
    just remove the spaces I put

    Actually it does computed the maxGrade, minGrade and average(if and only inputs are valid input).
    The problem is you did not print them. The other problem is you store the input in max and min before checking if they are valid inputs. Try to check if they are valid before storing them in min and max.

    try to print them after the outer loop but make sure to initialize your variable so you wont get compilation error regarding variables not initialize.

    what if I put 123 or -13, after execution, did you really get 10 valid input?
    as what I see, the program stores the value in min and max even if they are out of range (-1 > input > 100).
    do some algorithm that will avoid storing the input if they are not valid.
    Please check.
    Last edited by dicdic; February 26th, 2014 at 09:02 PM.

  5. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 26th, 2014)

  6. #4
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Thank you for both replies.
    I fixed the issue part wise, and I ran a debugger my file and there seems to be no issue. Now I am trying to run the file and it gives me an unusual output:
    Enter ten scores between 0 and a 100
    Score: 70
    Number of values = 140
    Maximum = 70.0
    Minimum = 70.0
    Average = 14.0

    Score: 80
    Number of values = 440
    Maximum = 80.0
    Minimum = 70.0
    Average = 44.0

    Score: 90
    Number of values = 1060
    Maximum = 90.0
    Minimum = 70.0
    Average = 106.0

    Score: 20
    Number of values = 2160
    Maximum = 90.0
    Minimum = 20.0
    Average = 216.0

    Score: 30
    Number of values = 4380
    Maximum = 90.0
    Minimum = 20.0
    Average = 438.0

    Score: 40
    Number of values = 8840
    Maximum = 90.0
    Minimum = 20.0
    Average = 884.0

    Score: 50
    Number of values = 17780
    Maximum = 90.0
    Minimum = 20.0
    Average = 1778.0

    Score: 60
    Number of values = 35680
    Maximum = 90.0
    Minimum = 20.0
    Average = 3568.0

    Score: 70
    Number of values = 71500
    Maximum = 90.0
    Minimum = 20.0
    Average = 7150.0

    Score: 80
    Number of values = 143160 ( is supposed to state 10)
    Maximum = 90.0
    Minimum = 20.0
    Average = 14316.0 (should be only two decimal places)


    Reformed code (Below):

    [code = java]
    import java.util.Scanner;

    public class moretest
    {
    public static void main( String [ ] args )
    {
    int total = 0;//stores 10 numbers
    int number;//stores current
    double minGrade = 101;
    double maxGrade = 0;
    float average;

    Scanner scan = new Scanner( System.in);

    for ( int i = 0; i < 1; i++ ) //Executes 1 time
    {
    System.out.println("Enter ten scores between 0 and a 100");

    for ( int n = 0; n < 10; n++ ) //Executes 10
    {
    System.out.println("Score: ");
    number = scan.nextInt ( );

    if (number > maxGrade){
    maxGrade = number;
    }

    if ( number < minGrade ){
    minGrade = number;
    }

    if ( -1 < number && 100 > number){
    total = total + number;

    i++;
    total += total;

    }

    else{
    System.out.println("Input value is not acceptable, try again.");
    }
    if (number > 0) {
    average = total/10;
    System.out.println("Number of values = " + total);
    System.out.println("Maximum = " + maxGrade);
    System.out.println("Minimum = " + minGrade);
    System.out.println("Average = " + average);
    }
    }
    }
    }
    }

    [/code]

    Thank you and I really appreciate the feedback!

  7. #5
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Now I am trying to run the file and it gives me an unusual output:
    what do you mean by unusual output?
    can you send here sample output? so we can see it?
    And I just want to ask, what is the sense of your outer loop?
    for ( int i = 0; i < 1; i++ ) //Executes 1 time
    the condition is hard coded. so it will run only once, so what is the need of loop?

    Average = 14316.0 (should be only two decimal places)
    you can use printf to make it two decimal places.
    System.out.printf("%.2f", Average);
    do you have any question?

    and please remove spaces in tag [code = java]

  8. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 26th, 2014)

  9. #6
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Thank you for responding!!

    The output is processed like this:
    Number of values = 71500
    Maximum = 90.0
    Minimum = 20.0
    Average = 7150.0

    They should look like this:
    Minimum score: 45
    Maximum score: 94
    Average score: 78.0

    If I get rid of "for( int i = 0; i < 1; 1++) The program executes the function only five times....for some reason.....
    Are there any other reasons why my program is not functioning correctly? Thanks again!!


    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 101;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
             for ( int i = 0; i < 1; i++ ) //Executes 1 time
             {
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int n = 0; n < 10; n++ ) //Executes 10 
             { 
              System.out.println("Score: ");
              number = scan.nextInt ( );
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( -1 < number && 100 > number){
                  total = total + number;
     
              i++;
              total += total;
     
              }
     
              else{
                  System.out.println("Input value is not acceptable, try again.");  
              }
              if (number > 0) { 
               average = total/10;
               System.out.println("Number of values = " + total);
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);
              }
            }           
           }
    }
    }

  10. #7
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    If I get rid of "for( int i = 0; i < 1; 1++) The program executes the function only five times....for some reason.....
    Are there any other reasons why my program is not functioning correctly? Thanks again!!
    No, it will still execute 10 times.

    The output is processed like this:
    Number of values = 71500
    Maximum = 90.0
    Minimum = 20.0
    Average = 7150.0

    They should look like this:
    Minimum score: 45
    Maximum score: 94
    Average score: 78.0
    if you want to remove Number of values = 71500 from output,
    then erase this in your statement System.out.println("Number of values = " + total);

    and the reason you got bugs from getting average is because of wrong arithmetic solution.
    total += total;
    that multiplies your total by 2. what is the reason for that?
    try to print the results outside your loop.
    question: do you need to print min, max and average every after input?
    would it be better to do that after getting all the input?
    Last edited by dicdic; February 26th, 2014 at 10:33 PM.

  11. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 26th, 2014)

  12. #8
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Thank you again, this is very helpful for me!

    I omitted total += total; What would be the correct arithmetic solution?

    I do not need to print it in every input, I would prefer to do it after getting all the other input. Not fully sure on how to do though...


    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 101;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
             {
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int n = 0; n < 10; n++ ) //Executes 10 
             { 
              System.out.println("Score: ");
              number = scan.nextInt ( );
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( -1 < number && 100 > number){
                  total = total + number;
     
              }
     
              else{
                  System.out.println("Input value is not acceptable, try again.");  
              }
              if (number > 0) { 
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);
              }
            }           
           }
    }
    }

  13. #9
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    What would be the correct arithmetic solution?
    what I meant when I said about wrong arithmetic solution is just to remove total += total
    Sorry if I made you confused with that. I'm not good in English

    Actually your solution is right
    just print the results after your loop
    in your code:
              if (number > 0) { 
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);
              }
    put that code outside your loop.
    I think that code would be before second to the last curly braces.
    and remove the condition if (number > 0).
    but i think it will still work even you don't remove the condition.

    have you tried to remove the outer loop that execute just once?

  14. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 26th, 2014)

  15. #10
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Thank you very much you have been extremely helpful!! I am really happy . The main problem that I have been trying to figure out has been solved and that makes me overjoyed. (I did remove the outer loop) Now all that is left is figuring out how to keep this from appearing:

    Maximum = 900
    Minimum = -10
    Average = 35.0


    and make sure that the program does not accept values less than 0 or greater than 100.

    My finalized code:

     
    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 101;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
             {
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int n = 0; n < 10; n++ ) //Executes 10 times
     
             { 
              System.out.println("Score: ");
              number = scan.nextInt ( );
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( -1 < number && 100 > number){
                  total = total + number;
     
              }
     
              else{
                  System.out.println("Input value is not acceptable, try again.");  
              }
     
            }
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);         
           }
             }
        }

  16. #11
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    (I did remove the outer loop)
    yes you did, but it seems that you did not remove its braces? please check although it wont a affect your program


    how to keep this from appearing:

    Maximum = 900
    Minimum = -10
    Average = 35.0
    I guess you tried to input -10 right?
    and the problem is your program cant handle this.

    you have this code below inside your loop:
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }

    it checks if the number is less than min, it also check if its greater than max, if so, you store it in min/max
    and after that, you have this code below:
              if ( -1 < number && 100 > number){
                  total = total + number;
     
              }
     
              else{
                  System.out.println("Input value is not acceptable, try again.");  
              }
    it checks if the input is valid right?

    so it means that you check(if must be min or max) and store input into min and max before checking if it is a valid input right (-1 < input < 100)?
    would it be better if you check if it is valid (-1 < input < 100) first before checking if it would be min or max?
    and if it is not valid, then you must not store it in you minGrade or maxGrade right?


    there are lots of ways to avoid executing statements inside your loop once a condition is satisfied.
    the one that i suggest is continue key word in java. that will only work for loop.
    if you don't know how continue works in loop, kindly see this link: Java Loops - for, while and do...while
    there is a tutorial in that link I've provided

    if you don't want continue, i think you can also use conditional statements if

    you can do it, you are almost there

  17. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 27th, 2014)

  18. #12
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    I fixed the brackets, thank you for pointing that out.
    Yes it does, and it actively tells me if the value is not accepted. The problem is that the program says it is not accepted, but the value is still included in the output, even after it has been declared "non-acceptable."
    (My input) : 0 < number && 100 > number, (is valid and accepted) I do not think I have a problem there...

    Whenever I put continue the program states that it is "unnecessary."

    Is there anything else that could be causing this program to not function optimally?

     
    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 10;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int i = 0; i < 10; i++ ) //Executes 10 times
             { 
              System.out.println("Score: ");
              number = scan.nextInt ( );
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( 0 < number && 100 > number){
                  total = total + number;
     
              }
     
              else{
                  System.out.println("Input value is not acceptable, try again.");  
              }
     
            }
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);         
           }
             }

    I cannot thank you enough for your assistance.

  19. #13
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    okay,
    what if you put a conditional statement right after you get the input?
    after number = scan.nextInt ();? so that you can check it right after you get the user's input(that is what i'm talking about earlier)
    let say you check the input if its less than 0 or greater 100.
    something like if(0 < input || 100 > input)
    and if so. print a validation message.
    and after printing validation message, that's where you put continue keyword, continue keyword in loop will make your loop do the blocks of code from the start, it will automatically skip all lines after continue keyword. try it.
    in that algorithm, once the user's input is invalid, it will automatically get another input (without doing the statements below that code)
    so once its invalid, it will not recorded in min or max, it will not also computed in average.

    --- Update ---

    did you figured it out?

  20. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 27th, 2014)

  21. #14
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    That worked out perfectly! I discovered two small glitches though. (Whenever I think I have finally solved this problem, a new problem appears...) This will be the last question I ask though, because everything else is minimal haha. Thank you for all of your assistance and your patience with a beginner with all these answers

    1) The system inputs everything perfectly , but if value is not accepted, does not prompt for a replacement value, so if score is not accepted the system moves on to the next input rather than asking to replace it. How would I change this? By adding another loop?

    2) Last question how do I get my system to number the scores? Score 1:, Score 2:, Score 3:, etc.. down to 10

     
    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 101;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int i = 0; i < 10; i++ ) //Executes 10 times
             { 
              System.out.println("Score 1: ");
              number = scan.nextInt ();
     
             if ( 100 < number || 0 > number){
               System.out.println("Input value is not acceptable, try again.");
               continue;
     
              } 
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( 0 < number && 100 > number){
                  total = total + number;
     
              } 
              }
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);         
           }
             }
    Thank you again and !

  22. #15
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    1) The system inputs everything perfectly , but if value is not accepted, does not prompt for a replacement value, so if score is not accepted the system moves on to the next input rather than asking to replace it. How would I change this? By adding another loop?
    look at your loop statement for ( int i = 0; i < 10; i++ )
    as you noticed, it will execute 10 times right?
    but actually, you can make it execute more than or less than 10 times
    if you put some statement inside it.
    let say in first loop, my input is invalid, then it will execute your statement continue right?
    then only 9 loop is left right? because next loop, variable i = 1 and loop will execute if i < 10 right?
    and your increment is i++.
    hmm, what if you modify your variable i whenever you get an invalid input?
    try to modify it before continue statement.
    that will work for sure. like subtract its current value by 1.

    2) Last question how do I get my system to number the scores? Score 1:, Score 2:, Score 3:, etc.. down to 10
    try to print score concatenated by variable i.

  23. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 27th, 2014)

  24. #16
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Would you be able to show an example I am a little bit confused? Sorry about the inconvenience...

  25. #17
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    okay i'll give you example, a simple example closer to your problem.
    I hope it is okay to the administrator of this forum to show some simple example.

    import java.util.Scanner;
     
    public class ControlLoop {
     
           public static void main(String[] args) {
                  Scanner scan = new Scanner(System.in);
                  int[] numbers = new  int[3];
                  for(int i = 0; i < 3; i++) { // executes 3 times
                         try {
                               System.out.println("Enter Number " + (i + 1));
                               numbers[i] = Integer.parseInt(scan.nextLine());
                         } catch (NumberFormatException e) {
                               System.err.println("Invalid input, not a valid integer");
                               i--; // this will subtract i by one, something like refreshing this part of loop.
                         }
                  }
                  System.out.println("\nThe inputs are");
                  for(int i : numbers) { // print numbers, will work only in java 6 and 7 i think
                         System.out.println(i);
                  }
           }
    }

    I just made the code here. not sure if it has compile error, please check if so.
    I hope that will help.
    try to analyze

    --- Update ---

    I edited the code, please check.
    make sure to name your java file same as the name to that class ControlLoop
    because its public

    note
    it can handle numbers only, so try to input letters.
    that error is something like yours.
    try to input invalid numbers like letters or words.. or spaces
    Last edited by dicdic; February 27th, 2014 at 08:02 PM.

  26. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 27th, 2014)

  27. #18
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    It worked out, thanks
    still having a problem with getting score 1:, score 2: etc, but everything else, perfect.
    What did you mean with, "try to print score concatenated by variable i?"

    import java.util.Scanner;
     
    public class moretest 
    {
        public static void main( String [ ] args )
        {
           int total = 0;//stores 10 numbers
           int number;//stores current
           int minGrade = 100;
           int maxGrade = 0;
           float average;
     
           Scanner scan = new Scanner( System.in);
     
              System.out.println("Enter ten scores between 0 and a 100");
     
             for ( int i = 0; i < 10; i++ ){ //Executes 10 times
     
              System.out.println("Score 1: "); 
              number = scan.nextInt ();
     
             if ( 100 < number || 0 > number){
               System.out.println("Input value is not acceptable, try again.");
               i--;
               continue;
     
              } 
     
              if (number > maxGrade){
                  maxGrade = number;
              }
     
              if ( number < minGrade ){  
                  minGrade = number;
              }
     
              if ( 0 < number && 100 > number){
                  total = total + number;
     
              }
     
              }
               average = total/10;
               System.out.println("Maximum = "  + maxGrade);
               System.out.println("Minimum = "  + minGrade);
               System.out.println("Average = "  + average);         
           }
             }
    Last edited by Knowledge_Feeds_The_Mind; February 27th, 2014 at 09:02 PM.

  28. #19
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    still having a problem with getting score 1:, score 2: etc, but everything else, perfect.
    are you asking to help you with that problem? or you can solve it yourself?

    "try to print score concatenated by variable i?"
    I said that because of this:
    2) Last question how do I get my system to number the scores? Score 1:, Score 2:, Score 3:, etc.. down to 10
    do you mean to store it in different variables? so that you can access it when you want?
    like printing score 1 - score 10?
    if so, you can use array.
    are familiar with array in java? if not kindly visit this link:
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    http://www.tutorialspoint.com/java/java_arrays.htm


    at first I thought that you are asking about how to print Score 1, Score 2...
    that is why I suggested you to print Score concatenated by your variable i
    you print it like this System.out.println("Score 1: ");
    I suggested you to print it like this System.out.println("Score " + i + ": ");

  29. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (February 27th, 2014)

  30. #20
    Junior Member Knowledge_Feeds_The_Mind's Avatar
    Join Date
    Feb 2014
    Posts
    24
    My Mood
    Amused
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    Thank you for all your help, I ran the program multiple times and it is perfect. I cannot thank you enough for your guidance and helpful nature. I hope that you have a great rest of the day!
    Thank you so much!!

    -Vex

  31. #21
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    241
    My Mood
    Tired
    Thanks
    6
    Thanked 57 Times in 55 Posts

    Default Re: Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.

    your welcome.. happy to help you

  32. The Following User Says Thank You to dicdic For This Useful Post:

    Knowledge_Feeds_The_Mind (March 3rd, 2014)

Similar Threads

  1. for loop that calculates the total of a series of numbers
    By JessicaCouture95 in forum Loops & Control Statements
    Replies: 8
    Last Post: November 3rd, 2013, 06:38 PM
  2. reading floats from file and output minimum and maximum temperatures
    By james_b in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 3rd, 2013, 11:10 PM
  3. Generating a random number from a range of inputted numbers
    By R0bert199O in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 25th, 2013, 01:48 PM
  4. Help with JFrame program that calculates average
    By ePerKar3 in forum AWT / Java Swing
    Replies: 3
    Last Post: November 4th, 2011, 08:48 AM
  5. Java program to find the minimum and maximum values of input data
    By awake77 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 20th, 2008, 04:12 PM