zoukankan      html  css  js  c++  java
  • return使用

     1 package day05;
     2 
     3 public class MethodDemo03 {
     4     public static void main(String[] args) {
     5         print(10, 20);
     6     }
     7 
     8     public static void print(int x, int y) {
     9         if (y < x) {
    10             System.out.println("你的输入错误,请检查!");
    11             //return;可以用于结束方法,也就是将方法从栈内存中弹出去,该过程称之为方法的弹栈
    12             return;
    13            // System.out.println();无法访问的语句,代码无效
    14         }
    15         System.out.println(x + "到" + y + "之间的奇数为;");
    16         for (int i = x; i <= y; i++) {
    17             if (i % 2 == 1) {
    18                 System.out.println(i);
    19             }
    20         }
    21     }
    22 }

    执行结果:

    欢迎批评指正,提出问题,谢谢!
  • 相关阅读:
    网页抓取
    基本数据结构
    小节
    顺序统计量
    线性时间排序
    快速排序
    堆排序 Heapsort
    大数运算
    趣味题,文本中洞的数量
    nginx config配置
  • 原文地址:https://www.cnblogs.com/xxeleanor/p/14218763.html
Copyright © 2011-2022 走看看