Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public class SmallestElement {
- public static void main(String[] args) {
- double[] array = {0, 1.2, 9.6, 6.8, -8.5, -1.3, 8.2};
- double[] array2 = {0, 1.2, 9.6, 6.8, -1.3,-8.5, -8.5, 8.2, -8.5};
- int smallestIndex=0;
- double smallestNumber= array2[0];
- for (int i =0; i<array2.length-1; i++) {
- if (smallestNumber > array2[i+1]) {
- smallestNumber=array2[i+1];
- smallestIndex= i+1;
- }
- }
- System.out.println("smallest number is "+ smallestNumber+ " and smallest index is "+smallestIndex);
- }
- }
RAW Paste Data


