要求说明:

输入三个整数x,y,z,请把这三个数由小到大输出。

实现代码:

第1种方法:

import java.util.Scanner;

public class xyzMaxMin{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入3个整数:");
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
System.out.println("从小到大排序后的结果:");
if (x < y && x < z) {
if (y < z) {
System.out.println(x + "<" + y + "<" + z);
} else {
System.out.println(x + "<" + z + "<" + y);
}
} else if (y < x && y < z) {
if (x < z) {
System.out.println(y + "<" + x + "<" + z);
} else {
System.out.println(y + "<" + z + "<" + x);
}
} else {
if (x < y) {
System.out.println(z + "<" + x + "<" + y);
} else {
System.out.println(z + "<" + y + "<" + x);
}
}
}
}

第2种方法:

import java.util.Scanner;

public class xyzMaxMin{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入3个整数:");
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
int i = 0;
if(x>y){
i=y;
y=x;
x=i;
}
if(x>z){
i=z;
z=x;
x=i;
}
if(y>z){
i=z;
z=y;
y=i;
}
System.out.println("从小到大排序后的结果:");
System.out.println(x+"<"+y+"<"+z);
}
}

第3种方法:

import java.util.Arrays;
import java.util.Scanner; public class xyzMaxMin{
public static void main(String[] args) {
int[] num = new int[3];
Scanner sc = new Scanner(System.in);
System.out.println("请输入3个整数:");
num[0] = sc.nextInt();
num[1] = sc.nextInt();
num[2] = sc.nextInt();
Arrays.sort(num);
System.out.println("从小到大排序后的结果:");
for (int i = 0; i < num.length; i++) {
System.out.print(num[i]+"\t");
}
}
}

最新文章

  1. codeforces 451D Count Good Substrings
  2. 使用sessionStorage得一个坑
  3. NSDate的处理:前一天、后一天等关于时区偏移的处理以及在数据库中的使用
  4. SQL入门学习2-聚合与排序
  5. 将SQL获取的信息传递到Email中
  6. 【模板】AC自动机(加强版)
  7. [笔试题目]使用Stringbuffer无 参的构造函数创建 一个对象时,默认的初始容量是多少? 如果长度不够使用了,自动增长多少倍?
  8. 新概念英语(1-37)Making a bookcase
  9. SQLAlchemy+Flask-RESTful使用(一)
  10. C语言实现邻接矩阵创建无向图&amp;图的深度优先遍历
  11. Error fetching command &#39;collectstatic&#39;: You&#39;re using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. Command &#39;collectstatic&#39; skipped
  12. iOS - 富文本直接设置文字的字体大小和颜色
  13. NET设计模式 第二部分 行为型模式(18):观察者模式(Observer Pattern)
  14. java截取电脑全屏
  15. Java学习之——Java Serializable
  16. LogHelp 日记分天记录,只记30天日记
  17. Excel Metadata
  18. 如何使用canvas进行2d绘图
  19. 期中HTML代码及技术博客
  20. 一篇博文将JavaScript尽收眼底

热门文章

  1. How exactly does Google AdWords work?
  2. k8s之ansible安装
  3. springboot 设置项目路劲后不能访问首页
  4. Redis cluster 集群部署和配置
  5. MySQL查询数据库表空间大小
  6. 转:Java多线程基础问题
  7. 洛谷八月月赛 II T1 题解
  8. LuoguP7441 「EZEC-7」Erinnerung 题解
  9. CF17A Noldbach problem 题解
  10. Linux使用docker安装Nginx