Java 程序:获取三个长整型值的较大者
首先,让我们声明并初始化三个长整型值 −
long val1 = 98799; long val2 = 98567; long val3 = 98768;
现在,使用以下条件查找三个长整型值的较大者 −
// checking for maximum if (val2 > val1) { val1 = val2; } if (val3 > val1) { val1 = val3; }
以下示例可获取最大值 −
示例
public class Demo { public static void main(String[] args) { long val1 = 98799; long val2 = 98567; long val3 = 98768; // displaying System.out.println("Number 1 = "+val1); System.out.println("Number 2 = "+val2); System.out.println("Number 3 = "+val3); // checking for maximum if (val2 > val1) { val1 = val2; } if (val3 > val1) { val1 = val3; } System.out.println("The greatest of three numbers: "+val1); } }
输出
Number 1 = 98799 Number 2 = 98567 Number 3 = 98768 The greatest of three numbers: 98799
广告