利用函数调运,实现数的交换(排大小)
来源:互联网 发布:高考的意义知乎 编辑:程序博客网 时间:2024/06/06 21:02
代码:
import java.util.Scanner;
public class textch {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader=new Scanner(System.in);
System.out.println("请连续输入三个数,每输入一个,按回车键以确认:");
int x=reader.nextInt();
int y=reader.nextInt();
int z=reader.nextInt();
ch CH=new ch();
CH.exchange(x,y,z);
}
}
public class ch {
void exchange(int a,int b,int c)
{
int count=0;
int temp=0;
if(a>b)
{
temp=a;
a=b;
b=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(a>c)
{
temp=a;
a=c;
c=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(b>c)
{
temp=b;
b=c;
c=temp;
count++;
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
if(count==0)
System.out.println("第"+count+"次交换的结果是"+a+","+b+","+c);
}
}
- 利用函数调运,实现数的交换(排大小)
- C_利用函数的引用调用实现两数的交换
- 用函数实现两个数的交换(指针)
- 用函数实现两个数的交换
- 使用函数实现两个数的交换。
- 使用函数实现两个数的交换;
- 使用函数实现两个数的交换。
- 使用函数实现两个数的交换
- 使用函数实现两个数的交换。
- 使用函数实现两个数的交换。
- 使用函数实现两个数的交换。
- 使用函数实现两个数的交换
- 使用函数实现两个数的交换
- 使用函数实现两个数的交换
- 函数实现两个数的交换
- 【C语言】实现交换两个数的大小
- 利用函数和指针实现最小数和第一个数交换,最大数和最后一个数交换
- 函数实现两个数交换
- 通过ajax上传excel
- 数据库——如何修改sys和system的密码
- LeetCode-17. Letter Combinations of a Phone Number
- 转自知乎
- 使用STS 构建 Spring Boot 项目
- 利用函数调运,实现数的交换(排大小)
- 监听器 ServletContextListener使用详解
- Shell 教程
- Scala函数式程序设计原理 week6 collections
- 5节点Hadoop分布式集群搭建经验分享
- PHPstudy的apache80端口被占用解决方法
- 1.开班信息
- KabyLake也就是第七代酷睿处理器安装win7 HD620驱动
- oracle创建数据库表空间—新手可以看看,大佬勿喷