java - 如何在 Java 中保持随机化文本?
问题描述
我只是想知道,也许你能帮助我。这是代码,也许你可以编辑它。
import java.util.Scanner;
public ststic void main string(args[]){
System.out.println("I want to keep randomize between following texts:")
//abc_123_def
//jaofn_3vfdsa
//nabdoew-8943
}
解决方案
我想这就是你要求的...
public static void main(String[] args) {
//task: show one of these texts randomly every time the user answers "yes"
String[] text = {"abc_123_def", "jaofn_3vfdsa", "nabdoew-8943"};
boolean bored = false;
Scanner s = new Scanner(System.in);
while (!bored) {
System.out.println("Would you like to keep randomizing?");
if (s.nextLine().equals("yes")) {
int rand_n = (int) Math.round(Math.random() * 2);
System.out.println("Random text: " + text[rand_n]);
}
else {bored = true;}
}
}
推荐阅读
- microsoft-graph-api - Microsoft Graph 托管内容 ID 包含斜杠
- javascript - 使用 ReactJs 在电子商务网站中过滤性别
- firebase - 通过静态 IP 地址连接到 Firebase Functions
- reactjs - 为什么 console.log 显示正确的数组但状态错误(ReactJS)
- excel - 在 Angular 5 中将 XLSX 列数据类型更改为数字
- django - 如何正确过滤 Django 中的类别?
- r - 在 R 中使用 cplot() 绘制边际效应时出错
- python - 基于字符串值 Plotly Python 的标记颜色
- botframework - Teams Bot 获取使用
- c# - xamarin:Device.BeginInvokeOnMainThread 和 MainThread.BeginInvokeOnMainThread 之间的区别