- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the smallest number in a Java array.
Example
Following is the required program.
public class Tester { public static int getSmallest(int[] a) { int temp; //sort the array for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } //return smallest element return a[0]; } public static void main(String args[]) { int a[] = { 11,10,4, 15, 16, 13, 2 }; System.out.println("Smallest: " + getSmallest(a)); } }
Output
Smallest: 2
- Related Articles
- Find the 3rd smallest number in a Java array.
- Find the 2nd smallest number in a Java array.
- Java program to find the smallest number in an array
- Java program to find the 2nd smallest number in an array
- Find the largest number in a Java array.
- Find the Smallest Positive Number Missing From an Unsorted Array
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- Remove smallest number in Array JavaScript
- Find the 3rd largest number in a Java array.
- Find the 2nd largest number in a Java array.
- Find the smallest and second smallest elements in an array in C++
- Program to Find the smallest number in an array of data in 8085 Microprocessor
- Find the Smallest element from a string array in JavaScript
- Python program to find the smallest number in a list
- Third smallest number in an array using JavaScript

Advertisements