Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with max, min, sorting array in given array

joker3000Apr 10 2015 — edited Apr 12 2015

Hi community, i'm JAVA learner and i don't know how to find max and min and sorting array without changing the original array and printing the results. Can anyone help me to fix my java code to find max, min and sorting please ?

Here is my java:

import java.util.Arrays;

import java.util.Random;

import java.util.*;

public class ProcessMarks {

        private static final int NMARKS = 125;

        private static final double mean = 65.0;

        private static final double std = 15.0;

        /**

         * Returns an array of NMARKS integer marks approximately normally distributed,

         * with specified mean (mean) and standard deviation (std),

         * and with values outside 0..100 removed.

         * @return the array of marks.

         */

        public static int[] getMarks() {

            Random rand = new Random(1001L);

            int mark;

            int[] theMarks = new int[NMARKS];

            int n = 0;

            while (n < NMARKS) {

                mark = (int) Math.round(std*rand.nextGaussian() + mean);

                if (mark >= 0 && mark <= 100)

                    theMarks[n++] = mark;

            }

            return theMarks;

        }

        public static int max(int[] getMarks) {

            int maximum = getMarks[0];

            for (int i=0; i<getMarks.length; i++) {

                if (getMarks[i] > maximum) {

                    maximum = getMarks;

                    }

                }

            return maximum;

            }

        /**

         * Test code

         * @param args not used

         */

        public static void main(String[] args) {

            System.out.println(" *Maximum Marks is = " + maximum);

             

            int[] testMarks = getMarks();

            for (int n = 0; n < testMarks.length; n++) {

                System.out.print(testMarks[n] + " ");

                if (n % 10 == 9)

                    System.out.println();

               

            }

        }

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2015
Added on Apr 10 2015
10 comments
3,158 views