java - ArithmeticException division by zero... how to fix this method? -


the purpose of method iterate through 2d array of integers called grid[][], , translate integers based on maximum , minimum values smaller range between 100 , 250 (the original minimum value becomes 100, original maximum value becomes 250, , in between calculated respectively). when method called, division 0 arithmeticexception occurs.

clearly i'm making logic mistakes here... don't see fix. can help?

public int greenvalues(int arrayval) {        int max = 0;     int min = 0;     int colorvalue = 0;     int temp;      (int = 0; < grid.length; i++) {  // finds maximum , minimum numbers in file          (int j = 0; j < grid.length; j++) {               if (max < grid[i][j]) {                 max = grid[i][j];                }             if (min > grid[i][j]) {                  min = grid[i][j];             }         }     }          int arrayrange = (max-min); // arrayval, arrayrange, , max , min 0         temp = (((arrayval-min) * color_range) / arrayrange) + 100;    // map values range of 100 - 250         colorvalue = temp;         return colorvalue;     } 

this line culprint producing arithmaticexcpetion.

temp = (((arrayval-min) * color_range) / arrayrange) + 100;

your calculating arrayrange dynamically don't know when value 0. can wrap line try catch block exception handling.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -