answersLogoWhite

0


Best Answer

int[] nums; // assume this is an array of length 5 and you want to find the largest

// finding it with a loop

int max = nums[0];

for(int i = 1; i < nums.length; ++i) {

if(nums[i] > max) {

max = nums[i];

}

}

// max is now the largest

// finding it manually

int max = Math.max(nums[0], Math.max(nums[1], Math.max(nums[2], Math.max(nums[3], nums[4]))));

// ugly, but effective

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

//Save this as gnum.java

public class gnum

{

double[] nums= {37,23,43,6.7,56}; //edit the numbers here to use different values

public static void main(Strings, args[])

{

System.out.print(getHighest());

}

public static double getHighest()

{

double highest = -999999999;

for (int x=0;x<5;x++)

{

if ( nums[x] > highest)

highest = x

}

return highest;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Assume that the first number is the maximum (store it to a variable called, for example, "maximum"). Loop through the array; every time you find an array element (a number) that is larger than the previous maximum, replace variable "maximum" with this number.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

system.out.print(Math.max(x, Math.max(y,z)))

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a java program to find the maximum number in an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


Write a c program to find the maximum of two numbers and print out with its position?

maxValue = function (array) {mxm = array[0];for (i=0; i&lt;array.length; i++) {if (array[i]&gt;mxm) {mxm = array[i];}}return mxm;}; i don't know


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Write a function in c that returns the largest value stored in an array-of-int Test the function in a simple program?

int max(int arr[], int arrSize){int maximum = arr[0];for (int i = 0; i < arrSize; i++){if (maximum < arr[i]){maximum = arr;}}return maximum;}


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


How do you write a program in C to find and display the sum of each row and column of a 2 dimensional array of type float?

array type


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i &lt; array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.