a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 109|回复: 0

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

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
【程序15】   
& ?6 c7 H- Q1 W! G题目:输入三个整数x,y,z,请把这三个数由小到大输出。   
( Y+ z0 @) c9 N8 T4 Rimport java.util.*;
, Y% x% a( {, wpublic class lianxi15 {
. Z& A, F% w) h& H6 e. wpublic static void main(String[] args) { & f' V: R3 j9 @% z" f
     input fnc = new input(); / \% }6 L7 }$ w5 Q
     int x=0, y=0, z=0;
: f/ C( V, X1 w+ s4 R     System.out.print("输入第一个数字:");
3 ^0 ~/ P4 L) s# W      x = fnc.input();
$ I- I# i+ Q2 v/ H% O) ?     System.out.print("输入第二个数字:");
! e  p. x+ S" g( s      y = fnc.input();
, h1 ]( L1 f0 P+ I: ^. j4 U     System.out.print("输入第三个数字:"); * W( r7 d% E+ k/ b/ C2 k1 _& T
      z = fnc.input();    4 a+ z5 G( p* D! h8 q
    if(x > y) {
2 v! V6 M. B* u- N      int t = x; " b# ]& D, E; {% L
      x = y; 9 @) c! m% n, r
      y = t; 7 a8 F3 U* ]1 H0 F. G% T" b
     }
& W& e; D/ F# j( P: W9 b5 z% j1 d    if(x > z) {   {; m1 J) ]( K+ p3 S/ q
      int t = x; ) q; W; {9 C# E- C
      x = z;
% J5 ?6 ~, W! d$ o+ W9 @6 A; C      z = t; 2 z7 G2 o; [1 `
     }
/ P$ h; N8 @, p4 }    if(y > z) { ; _+ }9 }8 X& x$ Z0 L% h8 ~
      int t = y;
; O; a# P5 f) N1 c) t: x2 I      y = z;
! P: h" G% H' |. Q      z = t;
" F2 n% D$ h" w6 f2 N     } 2 N4 o7 S8 Z, F. j0 ?& q6 B
    System.out.println( "三个数字由小到大排列为: "+x + " " + y + " " + z); . g8 T1 v6 e" Y: c
} ) L& K& c. d& v+ {% A; |0 z$ A3 o
} ; ~% u6 e0 _. S8 L9 c7 \
class input{ : O# m/ ~. N" f, U
public int input() {
* \" [* U4 v; g! |& z2 m! U     int value = 0; ' j" h. [- L+ o& Z6 T
     Scanner s = new Scanner(System.in); - p8 Z+ g0 p( A: P. U1 m% s2 G
     value = s.nextInt(); 5 ~- x; h; ]+ y6 Z; g
     return value; 5 ^* c  M7 w( [$ P6 O/ x2 k) z- Y: f
}
  C  l3 j. b6 M# i}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-5 18:28 , Processed in 0.202591 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表