标签:www JAVA int random --- static 色子 Math
编程语言【JAVA】编程(4)---摇色子
作业要求:
利用“ Math.random ( ) ”生成随机数的方法来模拟同时摇三个色子获得的点数;点数的多少不同,也会导致不同的输出结果;可适当对程序增添一些更有趣的功能;
作业优化:
import java.util.*;
public class 摇色子{
static int shu2;
static int a, b, c, mo, moo;
public static void main(String [] args){
int shu;
p("欢迎来到竞技场,这位其貌不扬的同学!\n");
p("请问是否进入游戏?\n");
p("请输入:1(进入)/0(退出) ");
shu=s();
if(shu==1){
p("正在载入《色子王2.0》....\n");
shaiZi();
}
else {
p("臭屌丝,没钱你来干嘛!\n");
}
}
public static void shaiZi(){
do {
a = (int) (Math.random() * 6 + 1);
b = (int) (Math.random() * 6 + 1);
c = (int) (Math.random() * 6 + 1);
int num = a + b + c;
p("您的点数为:" + num+"\n");
if (1 <= num && num < 7) {
p("孩子,消停回家种地去吧\n");
mo = -(int) (Math.random() * 100 + 1);
}
if (7 <= num && num < 13) {
p("有点实力嘛!\n");
mo = (int) (Math.random() * 100 + 1);
}
if (13 <= num && num <= 18) {
p("赌神大人,刚才是小人瞎了狗眼,请您不要在意\n");
mo = (int) (Math.random() * 200 + 1);
}
moo += mo;
p("这位同学,您现在筹码余额为:" + moo+"w\n");
p("请问是否继续赌局?\n");
p("请输入:1(继续)/0(退出)");
shu2=s();
}
while(shu2==1);
p("这位同学,您目前账户余额为:"+moo+"w\n");
p("欢迎下次光临!\n");
}
public static void p(String a){
System.out.print(a);
}
public static int s() {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
return a;
}
}
部分效果展示:
点击查看 (●'◡'●)
点击查看 ~( ̄▽ ̄)~*
博主能力有限,若程序有bug或有其他不当之处,请狠狠打脸博主 (~ ̄(OO) ̄)ブ
文章来源:https://www.cnblogs.com/Burning-youth/archive/2021/11/10/15532518.html
百度网盘搜索 |
www.ijzcn.cn |
阿哇教育 |
www.awaedu.com |
作文哥 |
www.zuowenge.cn |
搜码吧 |
www.somanba.cn |
标签:www,JAVA,int,random,---,static,色子,Math 来源: https://blog.csdn.net/wangxueying5172/article/details/121261175
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。