本文整理匯總了Java中java.lang.Math.max方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.max方法的具體用法?Java Math.max怎麽用?Java Math.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Math
的用法示例。
在下文中一共展示了Math.max方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: add
import java.lang.Math; //導入方法依賴的package包/類
public void add(double x) {
sum_x += x;
sum_xx += x*x;
num_x += 1.0;
min_x = Math.min(min_x,x);
max_x = Math.max(max_x,x);
}
示例2: getCaryString
import java.lang.Math; //導入方法依賴的package包/類
public String getCaryString(){
int humanNum = 0;
int timeLimitNum=99999;
int timeBonusNum=99999;
if(redBot){
humanNum+=(2*redDepth+4);//(redDepth/2+1)*4
}
if(blueBot){
humanNum+=(blueDepth/2+1);
}
if(timeLimit[1]!=Integer.MAX_VALUE){
timeLimitNum = timeLimit[1];
timeBonusNum = timeBonus;
}
if(screen==2){
boardStart = getBoard();
moveSequence = "";
}
String result = rules+","+Math.max(WIDTH,HEIGHT)+","+timeLimitNum+","+timeBonusNum+","+humanNum+","+boardStart+moveSequence;
return result;
}
示例3: height
import java.lang.Math; //導入方法依賴的package包/類
/**
* Return height of this tree
* Note this is recursive!
* Base case - no child nodes
* Recursive cases - L or R child node, or both
* @return int height of tree
*/
public int height() {
// Fill in placeholder "impossible" value of -1
int leftHeight = -1;
int rightHeight = -1;
// If left is null, then height from left on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height
if (left == null) {
leftHeight = 0;
} else {
leftHeight = left.height();
}
// If right is null, then height from right on down is 1
// We auto-add one as part of the return statement so set
// to 0.
// Otherwise, recurse to find height
if (right == null) {
rightHeight = 0;
} else {
rightHeight = right.height();
}
// Return the greater of left or right height
return 1 + Math.max(leftHeight, rightHeight);
}
示例4: main
import java.lang.Math; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// Size that a single card covers.
final int cardSize = 512;
WhiteBox wb = WhiteBox.getWhiteBox();
smallPageSize = wb.getVMPageSize();
largePageSize = wb.getVMLargePageSize();
allocGranularity = wb.getVMAllocationGranularity();
final long heapAlignment = lcm(cardSize * smallPageSize, largePageSize);
if (largePageSize == 0) {
System.out.println("Skip tests because large page support does not seem to be available on this platform.");
return;
}
if (largePageSize == smallPageSize) {
System.out.println("Skip tests because large page support does not seem to be available on this platform." +
"Small and large page size are the same.");
return;
}
// To get large pages for the card table etc. we need at least a 1G heap (with 4k page size).
// 32 bit systems will have problems reserving such an amount of contiguous space, so skip the
// test there.
if (!Platform.is32bit()) {
final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;
final long heapSizeDiffForCardTable = Math.max(Math.max(allocGranularity * cardSize, HEAP_REGION_SIZE), largePageSize);
Asserts.assertGT(heapSizeForCardTableUsingLargePages, heapSizeDiffForCardTable,
"To test we would require to use an invalid heap size");
testVM("case1: card table and bitmap use large pages (barely)", heapSizeForCardTableUsingLargePages, true, true);
testVM("case2: card table and bitmap use large pages (extra slack)", heapSizeForCardTableUsingLargePages + heapSizeDiffForCardTable, true, true);
testVM("case3: only bitmap uses large pages (barely not)", heapSizeForCardTableUsingLargePages - heapSizeDiffForCardTable, false, true);
}
// Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test
// everywhere.
final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte
final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;
final long heapSizeDiffForBitmap = Math.max(Math.max(allocGranularity * bitmapTranslationFactor, HEAP_REGION_SIZE),
Math.max(largePageSize, heapAlignment));
Asserts.assertGT(heapSizeForBitmapUsingLargePages, heapSizeDiffForBitmap,
"To test we would require to use an invalid heap size");
testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
}
示例5: var
import java.lang.Math; //導入方法依賴的package包/類
@GET
@Path("vars")
@Produces(MediaType.TEXT_HTML)
public Response var() throws IOException {
Map<String, String> variables = new LinkedHashMap<String, String>();
// Runtime
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
variables.put("state", getShutdownState() + "");
if (shuttingTime != 0) {
variables.put("shutdown-time", dateTimeFormat.format(new Date(shuttingTime)));
}
variables.put("start-time", dateTimeFormat.format(new Date(runtimeBean.getStartTime())));
variables.put("uptime-in-ms", runtimeBean.getUptime() + "");
variables.put("vm-name", runtimeBean.getVmName());
variables.put("vm-vender", runtimeBean.getVmVendor());
variables.put("vm-version", runtimeBean.getVmVersion());
//BuildServer Version and Id
variables.put("buildserver-version", GitBuildId.getVersion() + "");
variables.put("buildserver-git-fingerprint", GitBuildId.getFingerprint() + "");
// OS
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
variables.put("os-arch", osBean.getArch());
variables.put("os-name", osBean.getName());
variables.put("os-version", osBean.getVersion());
variables.put("num-processors", osBean.getAvailableProcessors() + "");
variables.put("load-average-past-1-min", osBean.getSystemLoadAverage() + "");
// Memory
Runtime runtime = Runtime.getRuntime();
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
variables.put("total-memory", runtime.totalMemory() + "");
variables.put("free-memory", runtime.freeMemory() + "");
variables.put("max-memory", runtime.maxMemory() + "");
variables.put("used-heap", memoryBean.getHeapMemoryUsage().getUsed() + "");
variables.put("used-non-heap", memoryBean.getNonHeapMemoryUsage().getUsed() + "");
// Build requests
variables.put("count-async-build-requests", asyncBuildRequests.get() + "");
variables.put("rejected-async-build-requests", rejectedAsyncBuildRequests.get() + "");
variables.put("successful-async-build-requests", successfulBuildRequests.get() + "");
variables.put("failed-async-build-requests", failedBuildRequests.get() + "");
// Build tasks
int max = buildExecutor.getMaxActiveTasks();
if (max == 0) {
variables.put("maximum-simultaneous-build-tasks-allowed", "unlimited");
} else {
variables.put("maximum-simultaneous-build-tasks-allowed", max + "");
}
variables.put("completed-build-tasks", buildExecutor.getCompletedTaskCount() + "");
maximumActiveBuildTasks = Math.max(maximumActiveBuildTasks, buildExecutor.getActiveTaskCount());
variables.put("maximum-simultaneous-build-tasks-occurred", maximumActiveBuildTasks + "");
variables.put("active-build-tasks", buildExecutor.getActiveTaskCount() + "");
StringBuilder html = new StringBuilder();
html.append("<html><body><tt>");
for (Map.Entry<String, String> variable : variables.entrySet()) {
html.append("<b>").append(variable.getKey()).append("</b> ")
.append(variable.getValue()).append("<br>");
}
html.append("</tt></body></html>");
return Response.ok(html.toString(), MediaType.TEXT_HTML_TYPE).build();
}
示例6: moveUp
import java.lang.Math; //導入方法依賴的package包/類
private void moveUp() {
top = Math.max(top - pageSize, 1);
bottom = Math.min(top + pageSize - 1, selection.size());
}
示例7: c_diameter
import java.lang.Math; //導入方法依賴的package包/類
public static int c_diameter(Node node){
if(node == null)return 0;
//heights of left & right subtrees
int c_left_height = c_height(node.left);
int c_right_height = c_height(node.right);
//diameters of left an right subtrees
int c_left_diameter = c_diameter(node.left);
int c_right_diameter = c_diameter(node.right);
//return
return Math.max(c_left_height+c_right_height+1,Math.max(c_left_diameter,c_right_diameter));
}
示例8: c_height
import java.lang.Math; //導入方法依賴的package包/類
public static int c_height(Node node){
if(node == null) return 0;
return 1 + Math.max(c_height(node.left),c_height(node.right));
}