java数字比较进阶

来源:互联网 发布:linux nano 全选 编辑:程序博客网 时间:2024/06/05 05:55
<script type="text/javascript">google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";google_ad_width = 336;google_ad_height = 280;//</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>第一个程序:/** * AWT Sample application * * @author * @version 1.00 05/03/08 */public class Chapter3 { int a,b,c; public void sort(int i,int q,int p) { if(i>q&&i>p) { a=i; if(q>p) { b=q; c=p; } else { b=p; c=q; } } if(q>i&&q>p) { a=q; if(i>p) { b=i; c=p; } else { b=p; c=i; } } if(p>i&&p>q) { a=p; if(i>q) { b=i; c=q; } else { b=q; c=i; } } System.out.print(a "/t"); System.out.print(b "/t"); System.out.print(c "/t"); } public static void main(String[] args) { System.out.println("OutPut from big to small"); Chapter3 cha=new Chapter3(); cha.sort(3,6,9); System.out.println(); }}第二个程序:/** * AWT Sample application * * @author * @version 1.00 05/04/26 */package MyPackage.Stream;import java.io.*;import java.util.*;public class Compare{public static void sort(double arry[],int n)//排序函数{ // for(int j=0;j<=n 1;j ) for(;;) { for(int q=0;q<n-1;q ) if(arry[q]>arry[q 1]) { double t; t=arry[q]; arry[q]=arry[q 1]; arry[q 1]=t; } n--; if(n<0) break; }}public static String In() throws IOException{String str;BufferedReader Input=new BufferedReader(new InputStreamReader(System.in));//数据流进行输入 str=Input.readLine();//读取行。 return str;} public static void main(String[] args) throws IOException { String st; int num; int i=0; double buffer[]; System.out.println("Input the Number to compare:"); st=In(); num=Integer.parseInt(st);//类型转换String->int buffer=new double[num];//动态定义数组存储数据 System.out.println("Input your Numbers:"); while(true)//保存 { st=In(); double f=Double.parseDouble(st);//类型转换String->double buffer[i]=f; i ; if(i==num) break; } sort(buffer,num);//进行数字的排序。 System.out.println("The Number to sort is:"); for(i=0;i<num;i )//排完序列后输出。 { System.out.println(buffer[i]); } }}第三个程序:/** * AWT Sample application * * @author * @version 1.00 05/04/26 */package MyPackage.Stream;import java.io.*;import java.util.*;public class Compare{public static String In() throws IOException{String str;BufferedReader Input=new BufferedReader(new InputStreamReader(System.in));//数据流进行输入 str=Input.readLine();//读取行。 return str;} public static void main(String[] args) throws IOException { String st; int num; int i=0; double buffer[]; System.out.println("Input the Number to compare:"); st=In(); num=Integer.parseInt(st);//类型转换String->int buffer=new double[num];//动态定义数组存储数据 System.out.println("Input your Numbers:"); while(true)//保存 { st=In(); double f=Double.parseDouble(st);//类型转换String->double buffer[i]=f; i ; if(i==num) break; } sort(buffer,num);//进行数字的排序。 Arrays.sort(buffer); System.out.println("The Number to sort is:"); for(i=0;i<num;i )//排完序列后输出。 { System.out.println(buffer[i]); } }}第四个程序:/** *输入有错误,给出提示,退出。 */import java.io.*;import java.util.*;public class Compare{public static String In() throws IOException{String str;BufferedReader Input=new BufferedReader(new InputStreamReader(System.in));//数据流进行输入 str=Input.readLine();//读取行。 return str;}public static void PutIn(double buffer[]) throws IOException{ String st; int i=0; while(true)//保存 { try { st=In(); double f=Double.parseDouble(st);//类型转换String->double buffer[i]=f; i ; if(i==buffer.length) break; } catch(NumberFormatException e) { e.printStackTrace(); System.out.println("程序异常,请按回车退出程序!"); System.exit(0); } } Arrays.sort(buffer);//进行数字的排序? System.out.println("The Number to sort is:"); } public static void PrintOut(double buffer[]) { for(int i=0;i<buffer.length;i )//排完序列后输出。 { System.out.println(buffer[i]); } } public static void main(String[] args) throws IOException { try { String st; int num; for(;;) { System.out.println("Input the Number to compare:"); st=In(); num=Integer.parseInt(st);//类型转换String->int if(num<=0)//判断数据的个数的正确性! { System.out.println("Please input a number which must bigger than zero!"); } else { break; } } double buffer[]=new double[num];//动态定义数组存储数据 System.out.println("Input your Numbers:"); PutIn(buffer); PrintOut(buffer); } catch(NumberFormatException e) { System.out.println("程序异常"); e.printStackTrace(); } }}本来还有一个,不知道放在那里了。不过我想这么多也够了。呵呵。
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 感冒了吃什么菜好的快 儿童咳嗽吃什么好的快 小孩咳嗽有痰吃什么好的快 金山快盘 快盘 登录 快盘论坛 快盘网页版 快盘下载 快盘登录 联想快盘 51快盘 金山快盘登录 企业快盘下载 快盘在线登录 怎样使用快盘 wps快盘怎么用 核桃怎么盘红的快 盘多 盘纤盘 盘刀 盘脚盘 滚盘 盘上 搓盘 月盘 盘故 曾侯尊盘 521gu盘 蛇盘疮用什么药好得快 快拍 快漫下载 快看看 快看影院 快看播放器 快穿今天好戏看 快穿今天有好戏看么 快穿之今天有好戏看么 攻略快穿文必看60本 快穿之今天有好戏看 快穿今天有好戏看 野画集快看