21xrx.com
2024-04-20 02:11:39 Saturday
登录
文章检索 我的文章 写文章
Java程序求三个数中最大的一个
2021-07-08 16:49:50 深夜i     --     --
J a v a

Java 程序寻找三个数中最大的一个,如果数不相等,则打印“numbers are not distinct”。 比较运算符“>”用于比较两个数字。 要从给定数字中找到最大的数字,您还可以使用数组。

 

Java编程源代码

import java.util.Scanner;


class Largest
{
  public static void main(String args[])
  {
    int x, y, z;
    System.out.println("Enter three integers");
    Scanner in = new Scanner(System.in);

    x = in.nextInt();
    y = in.nextInt();
    z = in.nextInt();

    if (x > y && x > z)
      System.out.println("First number is the largest.");
    else if (y > x && y > z)
      System.out.println("Second number is the largest.");
    else if (z > x && z > y)
      System.out.println("Third number is the largest.");
    else
      System.out.println("The numbers are not distinct.");
  }
}

 

程序输出:

下载最大的三个数字程序类文件。

如果您想从 10 个整数的列表中找出最大的数,那么使用上述方法并不容易; 相反,您可以使用数组。

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复