会计考友 发表于 2012-8-4 12:33:16

2012JAVA模拟试题及答案:编程题15

【程序15】   
题目:输入三个整数x,y,z,请把这三个数由小到大输出。   
import java.util.*;
public class lianxi15 {
public static void main(String[] args) {
   input fnc = new input();
   int x=0, y=0, z=0;
   System.out.print("输入第一个数字:");
      x = fnc.input();
   System.out.print("输入第二个数字:");
      y = fnc.input();
   System.out.print("输入第三个数字:");
      z = fnc.input();   
    if(x > y) {
      int t = x;
      x = y;
      y = t;
   }
    if(x > z) {
      int t = x;
      x = z;
      z = t;
   }
    if(y > z) {
      int t = y;
      y = z;
      z = t;
   }
    System.out.println( "三个数字由小到大排列为: "+x + " " + y + " " + z);
}
}
class input{
public int input() {
   int value = 0;
   Scanner s = new Scanner(System.in);
   value = s.nextInt();
   return value;
}
}
页: [1]
查看完整版本: 2012JAVA模拟试题及答案:编程题15