1. Member
Join Date
Nov 2009
Posts
12
Rep Power
0

## 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. Senior Member
Join Date
Nov 2009
Posts
236
Rep Power
11
Yeah it will work if you change all "mayor" to "major" and "numeros" to "numbers" or vis a versa

3. Senior Member
Join Date
Apr 2015
Posts
288
Rep Power
6
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. ## Re: Major number

This is a very old thread. I don't expect anyone remembers it.

5. Senior Member
Join Date
Nov 2009
Posts
236
Rep Power
11

## 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. Senior Member
Join Date
Apr 2015
Posts
288
Rep Power
6

## 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.

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

## 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

#### Posting Permissions

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