java数字比较进阶
2008-05-25 01:03
369 查看
google_ad_client = "pub-8800625213955058";
/* 336x280, 创建于 07-11-21 */
google_ad_slot = "0989131976";
google_ad_width = 336;
google_ad_height = 280;
//
第一个程序:
/**
* 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();
}
}
}
本来还有一个,不知道放在那里了。不过我想这么多也够了。呵呵。
/* 336x280, 创建于 07-11-21 */
google_ad_slot = "0989131976";
google_ad_width = 336;
google_ad_height = 280;
//
第一个程序:
/**
* 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();
}
}
}
本来还有一个,不知道放在那里了。不过我想这么多也够了。呵呵。
相关文章推荐
- java数字比较进阶
- Java进阶:深入equals方法对象相等比较
- Java进阶(五十一)XML:四种解析器(dom,sax,jdom,dom4j)原理及性能比较
- 为什么java 2个一样的数字比较 是false
- 随机出不重复的数字(不用随机出然后进行比较 JAVA实现)
- BToj 1031问题 B: KACA的数字排序 【大数比较--结构体sort && java大数比较】
- JAVA进阶----主线程等待子线程各种方案比较(转)
- Java字母加数字组合比较大小
- Flex数字类型和Java数字类型的比较
- java数字字符串比较大小
- Java进阶之欧拉工程 第十七篇【用英文写出1到1000的所有数字需要多少个字母?】
- 比较java与c语言中数字转换成字符的不同
- Java比较两个数字或者三个数字之间的大小
- Java 进阶 之 抽象类与接口 比较(二)
- Java字母加数字组合比较大小
- Java进阶--Integer与int的种种比较
- 浙大Java进阶mooc第二周作业---------有秒针计时的数字时钟
- Java进阶(三十四)Integer与int的种种比较你知道多少?
- Java进阶(三十四)Integer与int的种种比较你知道多少?
- Java—接受键盘输入的两个数字进行比较大小