Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static List<String> calculateResolutions(double dpi, double screenSize, boolean standard) { List<String> ret = new ArrayList<>(); double bothSquaredSum = Math.pow(dpi * screenSize, 2); for (int i = 0; i < 10000; i++) { double other = Math.sqrt(bothSquaredSum - Math.pow(i, 2)); double higher = Math.max(i, other), lower = Math.min(i, other); if (Double.isNaN(lower)) { continue; } if (standard) { double ratio = higher / lower; if (ratio == 4.0 / 3.0 || ratio == 16.0 / 9.0 || ratio == 16.0 / 10.0) { ret.add(String.format("%.0fx%.0f", higher, lower)); } } else { ret.add(String.format("%.0fx%.0f", higher, lower)); } } return ret; } }