Java程序----day1019
七彩选号程序
1 package com.lovo; 2 3 import java.util.Scanner; 4 /** 5 * 七星彩随机选号程序 6 */ 7 public class Test01 { 8 public static void main(String[] args) { 9 Scanner sc=new Scanner(System.in); 10 System.out.println("请输入随机注数:"); 11 int n=sc.nextInt(); 12 for(int i=1;i<=n;i++){ 13 for(int j=1;j<=7;j++){ 14 System.out.print((int)(Math.random()*10)+" "); 15 } 16 System.out.println(); 17 } 18 sc.close(); 19 } 20 21 }
百钱百鸡问题
1 package com.lovo; 2 /** 3 * 百千白鸡问题 4 * 5 */ 6 public class test12 { 7 public static void main(String[] args) { 8 for (int i = 0; i <= 20; i++) { 9 for (int j = 0; j <= 33; j++) { 10 int k=100-i-j; 11 if ((5 * i + 3 * j + k / 3 == 100) && k%3==0) { 12 System.out.printf("公鸡%d只\n母鸡%d只\n小鸡%d只\n\n", i, j, k); 13 } 14 } 15 } 16 } 17 }
craps赌博游戏
package com.lovo;
public class Test03 {
/*craps赌博游戏
*
*/
public static int roll(){
return (int)(Math.random()*6+1);
}
public static void main(String[] args) {
int firstpoit,currentpoint;
firstpoit=currentpoint=roll()+roll();
System.out.println("玩家摇出了"+currentpoint+"点");
boolean goon=false;
switch (currentpoint){
case 7:
case 11:
System.out.println("玩家胜!!");
break;
case 2:
case 3:
case 12:
System.out.println("庄家胜!!!");
break;
default:
goon=true;
}
while(goon){
currentpoint=roll()+roll();
System.out.println("玩家摇出了"+currentpoint+"点");
if(currentpoint==7){
System.out.println("庄家胜!!!");
goon=false;
}
else if(currentpoint==firstpoit){
System.out.println("玩家胜!!!");
goon=false;
}
}
}
}
浙公网安备 33010602011771号