Java tutorial
//package com.java2s; /* * WolframCA - an android application to view 1-dimensional cellular automata (CA) * Copyright 2013 Barry O'Neill (http://barryoneill.net/) * * Licensed under Apache 2.0 with limited permission from, and no affiliation with Steven * Wolfram, LLC. See the LICENSE file in the root of this project for the full license terms. */ public class Main { /** * Sanitize the provided zoom level * * @param val The value * @return If the value lies outsize the range 1-16, it will be set to 1 or 16 (whichever is closest). Within * that range, the value will rounded to the nearest multiple of 2 (eg 2, 4, 6,..). */ public static int sanitizeZoom(int val) { int step = 2, min = 1, max = 16; val = (Math.round(val / step)) * step; if (val <= min) { return min; } if (val >= max) { return max; } return val; } }