zoukankan      html  css  js  c++  java
  • 第5上机练习~~~~~~~~~~~~~~~~~~~~~~~~~~~~武汉一定要加油!!!

    1.编写一个程序,实现字符串大小写的转换并倒序输出。要求如下
    (1)使用for循环将字符串“ Hello world”从最后一个字符开始遍历
    (2)遍历的当前字符如果是大写字符,就使用 toLower Case()方法将其转换为小写字
    符,反之则使用 toUpper Case()方法将其转换为大写字符。
    (3)定义一个 StringBuffer对象,调用 append(方法依次添加遍历的字符,最后调用
    String Buffer对象的 toString(方法,并

    package chap3;
    
    import java.util.Random;
    
    public class apple {
        public static void main(String[] args) {
            String s1 = "Helloworld";
            StringBuffer a = new StringBuffer("java");
            char[] c1 = s1.toCharArray();
            for (int i = c1.length - 1; i >= 0; i--) {
                System.out.print(c1[i]);
                if (c1[i] >= 97) {
                    c1[i] = (char) (c1[i] - 32);
                    a.append(c1[i]);
                } else if (c1[i] <= 89) {
                    c1[i] = (char) (c1[i] + 32);
                    a.append(c1[i]);
                }
            }
            System.out.println();
            System.out.println(a.toString());
        }
    }

    将得到的结果输出。

    2.利用 Random类来产生5个20~30之间的随机整数
    提示:[m-m(mm均为整数,n<m)之间的随机数的公式为n+( new Random()
    t(mn-n+1)

    package chap3;
    
    import java.util.Random;
    
    public class apple {
        public static void main(String[] args) {
            Random r = new Random();
            int[] num = new int[5];
            for (int i = 0; i < num.length; i++) {
                num[i] = 20 + r.nextInt(30 - 20 + 1);
                System.out.println(num[i]);
            }
        }
    }

  • 相关阅读:
    Pthread使用总结
    OpenCV同态滤波
    重复文件重新创建
    Consider using the `--user` option or check the permissions.
    错误:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
    python tkinter模版
    tkinter页面卡死
    视频下载
    tkinter学习系列(三)之Label控件
    Entry小部件:
  • 原文地址:https://www.cnblogs.com/skyfail/p/12968378.html
Copyright © 2011-2022 走看看