Celebrating Children's Day: A Personalized Blessing Message Generator Implemented in Java

insert image description here

import java.util.*;

public class ChildrensDayMessageGenerator {
    
    
    public static void main(String[] args) {
    
    
        // 儿童名字列表
        List<String> childrenNames = Arrays.asList("小明", "小红", "小华", "小李", "小王");

        // 祝福消息列表
        List<String> messages = Arrays.asList(
            "祝你六一儿童节快乐,永远快乐!", 
            "祝你六一儿童节快乐,天天都有好心情!", 
            "祝你六一儿童节快乐,健康成长!", 
            "祝你六一儿童节快乐,学习进步!",
            "祝你六一儿童节快乐,天天开心!"
        );

        // 创建一个随机数生成器
        Random rand = new Random();

        // 遍历每个儿童名字
        for (String child : childrenNames) {
    
    
            // 随机选择一个祝福消息
            String message = messages.get(rand.nextInt(messages.size()));
            
            // 打印祝福消息
            System.out.println(child + "," + message);
        }
    }
}

When you run this program, it will randomly generate a blessing message for each child in the list, and print each child's name and the blessing message they got to the console.

Happy Children's Day!

Guess you like

Origin blog.csdn.net/tuzajun/article/details/130980184