Welcome to the Webmaster Forum.
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Dec 2015
    Posts
    31

    Find largest and smallest number in array?

    Hi,
    I would like to know,
    How to find largest and smallest number in array?

  2. #2
    Member
    Join Date
    Dec 2017
    Location
    Santa Clara, California, USA
    Posts
    81

    Re: Find largest and smallest number in array?

    /*
    Find Largest and Smallest Number in an Array Example
    This Java Example shows how to find largest and smallest number in an
    array.
    */
    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
    */

 

 

Similar Threads

  1. Smallest part in body..?
    By angilpari1122 in forum General Talk
    Replies: 2
    Last Post: 03-09-2017, 12:13 AM
  2. Largest and smallest city in the world...?
    By maulanakhadim in forum General Talk
    Replies: 1
    Last Post: 09-13-2016, 03:04 AM
  3. Using the array() Construct to Preload an Array
    By chinmay.sahoo in forum PHP
    Replies: 2
    Last Post: 08-08-2016, 06:15 AM
  4. How can we find the number of rows in a result set using PHP?
    By chinmay.sahoo in forum Coding & Programming
    Replies: 2
    Last Post: 03-28-2016, 05:20 AM
  5. PHP Array
    By Prince25 in forum Coding & Programming
    Replies: 2
    Last Post: 09-27-2013, 12:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Back to top

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203