- public class FindLargestSmallestNumber {
- public static void main(String[] args) {
- //array of 10 numbers
- int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};
- //assign first element of an array to largest and smallest
- int smallest = numbers[0];
- int largetst = numbers[0];
- for(int i=1; i< numbers.length; i++)
- {
- if(numbers[i] > largetst)
- largetst = numbers[i];
- else if (numbers[i] < smallest)
- smallest = numbers[i];
- }
- System.out.println("Largest Number is : " + largetst);
- System.out.println("Smallest Number is : " + smallest);
- }
- }
- /*
- Output of this program would be
- Largest Number is : 98
- Smallest Number is : 23
- */
Sunday, September 4, 2016
Java Program To Find Largest and Smallest Number in an Array
Bhanu Namikaze
Author & Editor
Bhanu Namikaze is an Ethical Hacker, Passionate Blogger, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors, Surfing and Social Networking. Feel Free To Contact Me @ Bhanu.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment