answersLogoWhite

0

In Java, assuming you already created an array of int's, called myArray:

int max = myArray[0];
int sum = 0;
for (int i = 0; i < myArray.length; i++)
{
sum += myArray[i];
if (myArray[i] > max)
sum = myArray[i]

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

How do you sort the given contents of an array?

You would sort the given elements of an array by a bubble sort or heap sort code!!


What is the algorithm for finding largest and smallest of given number?

To find the largest number: Assume (temporarily) that the first number is the largest number. You might call this the "largest number found so far". Then, for each number after the first one, compare the number with the largest number found so far. If the new number in the list is larger, call that one the "largest number found so far". Repeat for each number. After processing all the numbers, the "largest number found so far" will simply be the largest number.For example, if your list is (5, 2, 8, -1), you start assuming that 5 (the first number in the list) is the largest number. You compare with 2 - "5" is still the largest number, since 2 is smaller. When you compare with 8, you find that 8 is larger, so you replace your "largest number" with 8. "-1" is smaller, so nothing changes. Since we processed the entire list, the largest number is now 8.You can do the same - mutatis mutandis - to find the smallest number.


How many structure variables of a given type can you use in a C program?

You can use unlimited number of variables for a structure and you can also declare array of structures.


What conditions must be satisfied by the entire elements of any given array?

All elements of any given array must satisfy the same data type requirement, meaning they should be of the same data type for the array to be well-defined and properly utilized.


A given source statement may be converted to any number of machine-level instructions with what?

Compiler

Related Questions

How can you get position of number from given some number by using array in c language?

Traverse the array from index 0 until you find the number. Return the index of that number.


What is the minimum absolute difference between any two elements in a given array?

The minimum absolute difference between any two elements in a given array is the smallest positive number that can be obtained by subtracting one element from another in the array.


How does the number of factors determine the number of different rectangular arrays that can be made for given number?

Each factor pair is an array.


Find index number of an given array?

For instance, you have array of type int with a name myArray, and you do not know size of the array. You can use following statement to get it:int arraySize = myArray/myArray[0];arraySize gives you number of elements in myArray.


How do you sort the given contents of an array?

You would sort the given elements of an array by a bubble sort or heap sort code!!


How can one efficiently identify and count the number of contiguous subarrays within a given array?

To efficiently identify and count the number of contiguous subarrays within a given array, you can use a sliding window approach. Start with two pointers that define the subarray, and move them based on certain conditions. By keeping track of the count as you iterate through the array, you can efficiently identify and count the contiguous subarrays.


What is the largest number of individuals a given environment can support called?

The name given to the largest population than an environment can support is called Carrying Capacity.


C program to fine the largest of 10 given number?

first sort the ten numbers in descending order and print the first number. That will be the largest no


What is the size of the largest sub grid within the given grid?

The size of the largest sub grid within the given grid is determined by the number of rows and columns it contains.


Draw a flow chart find the largest number of given 3 numbers?

no


What is the range of a series of numbers?

In any given set, the range is the smallest number subtracted from the largest number.


What is the largest number roman numeral that begins with the given indicated symbol V?

The largest number roman numeral that begins with the symbol &quot;V&quot; is &quot;VIII&quot; which represents the number 8.