Write a program to find maximum and minimum number in array?



Write a program to find maximum and minimum number in array?..

Answer / Preeti Arora

Here is a simple Java program to find the maximum and minimum numbers in an array:n```javanpublic class FindMaxMin {n public static void main(String[] args) {n int[] arr = {1, 5, 3, 7, 2};n int max = arr[0];n int min = arr[0];n for (int i = 1; i < arr.length; i++) {n if (arr[i] > max) {n max = arr[i];n }n if (arr[i] < min) {n min = arr[i];n }n }n System.out.println("Maximum number: " + max);n System.out.println("Minimum number: " + min);n }n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

how many types of Inheritance?

1 Answers   Impetus,


Explain an intermediate language?

1 Answers  


can we overload main method?

8 Answers   TCS,


What is Difference between Serializable and Externalizable in Java serialization?

1 Answers   Cognizant, IBM,


What are the topics in advance java?

1 Answers  


What are the different types of inheritance in java?

1 Answers  


What is the default modifier in Interface?

5 Answers  


Which is better stringbuilder or stringbuffer?

1 Answers  


Can an unreferenced object be referenced again?

1 Answers  


What is final keyword?

1 Answers  


What is a nullable field?

1 Answers  


What do you mean by byte code?

1 Answers  


Categories