用java做一个模拟彩票程序_JAVA模拟----- 彩票机子-----抽奖过程的实例化
/*
時間:
2012-10-05
作者:
煙大陽仔
程序要求:
模擬彩票抽獎機的功能編寫一個程序,實現隨即輸出六個號碼
程序解釋:
該段程序沒有傳遞參數
*/
class Day1005_Caipiao
{
public static void main(String[] args)
{
System.out.println("估計彩票開獎號碼:");
random_num();
}
static void random_num()
{
int v;
String str="";
for (int i=1;i<7 ;i++ )
{
v=(int)(Math.random()*42)+1;
str=str+v+" ";
}
System.out.println(str);
}
}
/*
時間:
2012-10-05
作者:
煙大陽仔
程序要求:
模擬彩票抽獎機的功能編寫一個程序,實現隨即輸出六個號碼
程序解釋:
該段程序傳遞了參數實現了功能
*/
class Day1005_Caipiao2
{
public static void main(String[] args)
{
System.out.println("彩票的中獎號碼為:");
int n=7;
random_num(n);
}
static void random_num(int n)
{
String str="";
int v;
for (int i=0;i
{
v=(int)(Math.random()*42)+1;
str=str+v+" ";
}
System.out.println(str);
}
}
/*
時間:
2012-10-05
作者:
煙大陽仔
程序要求:
模擬彩票抽獎機的功能編寫一個程序,實現隨即輸出六個號碼
程序解釋:
該段程序運用返回值實現了功能
*/
class Day1005_Caipiao3
{
public static void main(String[] args)
{
System.out.println("中獎號碼為:");
String str="";
str=random_num();
System.out.println(str);
}
static String random_num()
{
String str="";
int v;
for (int i=0;i<7 ;i++ )
{
v=(int)(Math.random()*42)+1;
str=str+v+" ";
}
return str;
}
}
總結
以上是生活随笔為你收集整理的用java做一个模拟彩票程序_JAVA模拟----- 彩票机子-----抽奖过程的实例化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AMD 前 3 代 EPYC 处理器曝出
- 下一篇: java dos平台压缩_Dos命令 压