daily pastebin goal
41%
SHARE
TWEET

Smallest Element

therrontelford Jan 29th, 2018 (edited) 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class SmallestElement {
  3.  
  4.     public static void main(String[] args) {
  5.         double[] array = {0, 1.2, 9.6, 6.8, -8.5, -1.3, 8.2};
  6.         double[] array2 = {0, 1.2, 9.6, 6.8, -1.3,-8.5, -8.5, 8.2, -8.5};
  7.         int smallestIndex=0;
  8.         double smallestNumber= array2[0];
  9.         for (int i =0; i<array2.length-1; i++) {
  10.             if (smallestNumber > array2[i+1]) {
  11.                 smallestNumber=array2[i+1];
  12.                 smallestIndex= i+1;
  13.             }
  14.         }
  15.         System.out.println("smallest number is "+ smallestNumber+ " and smallest index is "+smallestIndex);
  16.  
  17.     }
  18.  
  19. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top