javaѧϰ֮· Ö® »ù±¾Óï·¨-³ÌÐòÁ÷³Ì¿ØÖÆ-£¨if-else)Óï¾äÁ·Ï°Ìâ

¤… ÄäÃû¼¼ÊõÓû§   ¤b 2020-12-23 17:43   ¤z 485   ¤k 0
  1. public class IfTest {
  2. public static void main(String[] args) {
  3. int a = 200;
  4. /*
  5. if (²¼¶û±í´ïʽ) {
  6. Óï¾ä¿é // ÒªÏëÖ´ÐбØÐë²¼¶û±í´ïÊ½ÎªÕæ
  7. }*/
  8. if (a == 20) {
  9. System.out.println("a==20"); // ÓÐÌõ¼þµØÖ´ÐÐ
  10. }
  11. System.out.println("after if...");
  12. }
  13. }
  14. class IfTest2 {
  15. public static void main(String[] args) {
  16. int a = 20;
  17. if (a == 200) {
  18. System.out.println("a==20");
  19. } else { // ·ñÔò, Èç¹ûifÖеÄÌõ¼þΪ¼Ù, Ö´ÐÐÏÂÃæµÄÓï¾ä
  20. System.out.println("else");
  21. }
  22. System.out.println("after if else ...");
  23. }
  24. }
  25. class IfTest3 {
  26. // ·ÖÖ§ : ¶à¸öÌõ¼þ, Ö»ÔÊÐíÓÐÒ»¸öÖ´ÐÐ
  27. public static void main(String[] args) {
  28. int a = 20;
  29. if (a == 10) {
  30. System.out.println("a==10");
  31. } else if (a == 20) {
  32. System.out.println("a==20");
  33. } else if (a == 30) {
  34. System.out.println("a==30");
  35. } else {
  36. System.out.println("else");
  37. }
  38. System.out.println("after if else if ...");
  39. }
  40. }
  41. class Exer3 {
  42. public static void main(String[] args) {
  43. /*
  44. ´ÓÃüÁîÐвÎÊý½ÓÊÕСÃ÷µÄÆÚÄ©³É¼¨¡£
  45. µ±³É¼¨Îª100·Öʱ£¬½±ÀøÒ»Á¾BMW£»
  46. µ±³É¼¨Îª£¨80£¬99]ʱ£¬½±ÀøÒ»¸ǫ̈iphone6s£»
  47. if (80 < score <= 99)
  48. µ±³É¼¨Îª[60,80]ʱ£¬½±ÀøÒ»±¾²Î¿¼Ê飻
  49. ÆäËüʱ£¬Ê²Ã´½±ÀøÒ²Ã»ÓС£
  50. Ìáʾ: ´ÓÃüÁîÐвÎÊý»ñÈ¡ÕûÊýµÄ´úÂë:
  51. int score = Integer.parseInt(args[0]);
  52. */
  53. int score = Integer.parseInt(args[0]);
  54. if (score > 100 || score < 0) {
  55. System.out.println("ÊäÈëµÄÊý¾Ý·Ç·¨");
  56. } else if (score == 100) {
  57. System.out.println("½±ÀøÒ»Á¾BMW");
  58. } else if (score > 80 && score <= 99) {
  59. System.out.println("½±ÀøÒ»¸ǫ̈iphone6s");
  60. } else if (score >= 60 && score <= 80) {
  61. System.out.println("½±ÀøÒ»±¾²Î¿¼Êé");
  62. } else {
  63. System.out.println("ʲô½±ÀøÒ²Ã»ÓÐ");
  64. }
  65. }
  66. }
  67. /*
  68. ´ó¼Ò¶¼ÖªµÀ£¬Äд󵱻飬Ů´óµ±¼Þ¡£ÄÇôŮ·½¼Ò³¤Òª¼ÞÅ®¶ù£¬µ±È»ÒªÌá³öÒ»¶¨µÄÌõ¼þ£º¸ß£º180cmÒÔÉÏ£»¸»£º²Æ¸»1ǧÍòÒÔÉÏ£»Ë§£ºÊÇ¡£
  69. Èç¹ûÕâÈý¸öÌõ¼þͬʱÂú×㣬Ôò£º¡°ÎÒÒ»¶¨Òª¼Þ¸øËû!!!¡±
  70. Èç¹ûÈý¸öÌõ¼þÓÐÎªÕæµÄÇé¿ö£¬Ôò£º¡°¼Þ°É£¬±ÈÉϲ»×㣬±ÈÏÂÓÐÓà¡£¡±
  71. Èç¹ûÈý¸öÌõ¼þ¶¼²»Âú×㣬Ôò£º¡°²»¼Þ£¡¡±
  72. */
  73. public class IfTest {
  74. public static void main(String[] args) {
  75. int heigh = Integer.parseInt(args[0]);
  76. int money = Integer.parseInt(args[1]);
  77. boolean b = Boolean.parseBoolean(args[2]);
  78. if (heigh > 180 && money > 1000 && b == true) {
  79. System.out.println("ÎÒÒ»¶¨Òª¼Þ¸øËû!!!");
  80. } else if (heigh > 180 || money > 1000 || b == true) {
  81. System.out.println("¼Þ°É£¬±ÈÉϲ»×㣬±ÈÏÂÓÐÓà");
  82. } else {
  83. System.out.println("²»¼Þ£¡");
  84. }
  85. }
  86. }
  87. //±àд³ÌÐò£º½ÓÊÕÈý¸öÃüÁîÐÐ×Ö·û´®²¢×ª»»ÎªÕûÊý·Ö±ð´æÈë±äÁ¿num1¡¢num2¡¢num3£¬¶ÔËüÃÇ
  88. //½øÐÐÅÅÐò(ʹÓà if-else if-else),²¢ÇÒ´ÓСµ½´óÊä³ö¡£
  89. public class IfTest1 {
  90. public static void main(String[] args) {
  91. int num1 = Integer.parseInt(args[0]);
  92. int num2 = Integer.parseInt(args[1]);
  93. int num3 = Integer.parseInt(args[2]);
  94. if (num1 > num2){
  95. if (num3 > num1){
  96. System.out.println(num2 + "," + num1 + "," + num3);
  97. } else if (num2 > num3) {
  98. System.out.println(num3 + "," + num2 + "," + num1);
  99. } else{
  100. System.out.println(num2 + "," + num3 + "," + num1);
  101. }
  102. }else {
  103. if (num3 > num2) {
  104. System.out.println(num1 + "," + num2 + "," + num3);
  105. }else if(num1 > num3) {
  106. System.out.println(num3 + "," + num1 + "," + num2);
  107. }else {
  108. System.out.println(num1 + "," + num3 + "," + num2);
  109. }
  110. }
  111. }
  112. }
  113. class IfTest11 {
  114. public static void main(String[] args) {
  115. int num1 = Integer.parseInt(args[0]);
  116. int num2 = Integer.parseInt(args[1]);
  117. int num3 = Integer.parseInt(args[2]);
  118. //±È½Ï½»»»3´Î
  119. //1ºÍ2
  120. if (num1 > num2) {
  121. int tmp = num1;
  122. num1 = num2;
  123. num2 = tmp;
  124. }
  125. //2ºÍ3
  126. if (num2 > num3) {
  127. int tmp = num2;
  128. num2 = num3;
  129. num3 = tmp;
  130. }
  131. //1ºÍ2
  132. if (num1 > num2) {
  133. int tmp = num1;
  134. num1 = num2;
  135. num2 = tmp;
  136. }
  137. System.out.println(num1 + "," + num2 + "," + num3);
  138. }
  139. }
·ÖÏíµ½ :
0 ÈËÊÕ²Ø
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

»ý·Ö:7942463
Ìû×Ó:1588486
¾«»ª:0
ÆÚȨÂÛ̳ ÆÚȨÂÛ̳
·¢²¼
ÄÚÈÝ

ÏÂÔØÆÚȨÂÛ̳ÊÖ»úAPP