• 5.26


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

    public class HellloWord {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             String str = "HelloWorld";
                char[] ch = str.toCharArray();
                StringBuffer buffer = new StringBuffer();
                for(int i=str.length()-1;i>=0;i--){
                    if((ch[i]>='A')&&(ch[i]<='Z')){
                        buffer.append(String.valueOf(ch[i]).toLowerCase());
                    }else if((ch[i]>='a')&&(ch[i]<='z')){
                        buffer.append(String.valueOf(ch[i]).toUpperCase());
                    }
                }
                System.out.println(buffer.toString());
        }
     
    }

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

    import java.util.Random;
     
    public class HellloWord {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Random rand = new Random();
            int[] num = new int[5];
            for(int i=0;i<num.length;i++){
                num[i] = 20+rand.nextInt(31);
            System.out.println(num[i]);   
            }
        }
     
    }
  • 相关阅读:
    jwt原理
    图书管理系统后端
    图书管理系统前端
    图书管理前端页面
    Linux多任务: exec 和fork()的联用
    CPU 字长与存储器位宽不一致处理
    关键字volatule
    linux C 中断程序:利用队列保存中断类型
    Linux下的Make与Makefile
    C :assert() 的用法
  • 原文地址:https://www.cnblogs.com/xiaomoa/p/12966766.html
Copyright © 2020-2023  润新知