method in read from file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miss time
    New Member
    • Jun 2007
    • 16

    #1

    method in read from file

    Hi all;

    I have some difficalty to write some method in read from file.I write a method of reading from file that contains grades obtained by students in 4 different courses.and this method reads these values and prints the minimum, maximum and average of grades for each student. It should also print the same for all the students. I write the method of printing avarage and also i try to write min and max method but when I compile there no min and max grade . can you explan to me what should i do.
    i put this code of finding min and max in readFromFile method

    for(int i=1;i<arr.lengt h;i++)
    {
    if ( arr[i] > max ) max = arr[i];
    }
    System.out.prin tln( max);
    }
    for(int i=1;i<arr.lengt h;i++)
    {
    if ( arr[i] < min ) min = arr[i];

    System.out.prin tln(min);

    }
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    If you are new to using forums you may want to review the posting tips. It will help you get better responses. For starters when posting code please use code tags. Just posting code as text makes it very hard to read. Also just saying it does not work does not provide much to go on. What happens? Is there a run time error, does it not compile, does it print out nulls, or just print out blank spaces, etc.

    Have you verified that there are actually values in the array? You may want to add a temporary test line as I have shown below to verify values are being passed. Also it also looks like your braces may not match up. There are three closing braces in the code shown, but only two opening braces. Java compilers allow you to do if tests with out using braces, but it is a bad habit to get into. I can cause a lot of confusion.


    [CODE=java]

    for(int i=1;i<arr.lengt h;i++) {
    System.out.prin tln( "Array value found : "+arr[i] );
    if ( arr[i] > max ) {
    max = arr[i];
    }
    }

    System.out.prin tln( max);

    for(int i=1;i<arr.lengt h;i++) {
    if ( arr[i] < min ) {
    min = arr[i];
    }
    }

    System.out.prin tln(min);

    [/CODE]
    Last edited by r035198x; Apr 7 '08, 03:20 PM. Reason: added =java to the opening code tag

    Comment

    Working...