Results 1 to 7 of 7

Thread: Major number

  1. #1
    lobodelbosque is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default Major number

    Hi:

    I have done a class that select the major number from an array of numbers. I'd like to know if its good.

    Thanks.

    public class MajorNumber {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    int numbers[]={5,7,8,8,8,8,19,9,9,10,1};
    int i=0;
    int major=0;
    int j=0;int k=1;


    for(i=0;i<numeros.length -1;i++)
    {


    if(numeros[j]>numeros[k])
    {
    mayor=numeros[j];
    k++;
    }
    else
    {
    mayor=numeros[k];
    j=k;
    k++;

    }


    }

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    236
    Rep Power
    11

    Default

    Yeah it will work if you change all "mayor" to "major" and "numeros" to "numbers" or vis a versa

  3. #3
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default

    Is the major number (in array) the same as the biggest one? Once I have the testing to define 2 major numbers in array just with one (for) cycle. I tried to do it as to find 2 biggest numbers, but my coleague for testing told me that major major number is the most frequent number -- I was unable to check is it so, was it joke or bogus suggestion. Here I see that the major number is the largest one.
    So what is true, what is major number? Before it I have the task to define even 3 largest numbers but it was not defined as major ones?

    Is the major number (in array) the same as the biggest one? Once I have the testing to define 2 major numbers in array just with one (for) cycle. I tried to do it as to find 2 biggest numbers, but my coleague for testing told me that major number is the most frequent number -- I was unable to check is it so, was it joke or bogus suggestion. Here I see that the major number is the largest one.
    So what is true, what is major number? Before it I have the task to define even 3 largest numbers but it was not defined as major ones?
    Last edited by Norm; 07-28-2017 at 09:39 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Major number

    This is a very old thread. I don't expect anyone remembers it.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    236
    Rep Power
    11

    Default Re: Major number

    If you google "major number in array" you get both max and majority number. You'll have to clarify with whoever is telling you to find the major number in an array.

  6. #6
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Major number

    I was tasked about two "major number" (not majority -- the aforementioned coleague told he knows the English very well so it should be so). To cast out inappropriate option you could suggest is it theoretically find 2 most frequent (if it meant as major) numbers in array with just one for or while cycle? Anyway what approach to find most frequent number -- should there to be some additional array that doubles the original array but with its frequency numbers but recurrent numbers could be void with its frequencies.
    Anyway I searched google with "major number" and nothing reliable did not found.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Major number

    The above code, when variables are properly named and braces are matched up, prints the maximum of the array. And it is done in an overly complex manner. Finding the maximum (or minimum of an array or list) is trivial and takes only a few statements. I have not heard the term "major element" before.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 08-07-2009, 12:14 PM
  2. Replies: 1
    Last Post: 07-16-2009, 02:15 PM
  3. Replies: 1
    Last Post: 11-03-2008, 02:38 PM
  4. Software Engineer...Computer Science Major
    By giganews35 in forum Introductions
    Replies: 2
    Last Post: 09-14-2008, 09:19 AM
  5. line number
    By kazitula in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 10:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •