Java 1019

package com.lovo;
import java.util.Scanner;

/**
 * 七星彩;
 * @author 周博
 */

public class Test04 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("请输入您需要购买的注数:");
		if(sc.hasNextInt()){
				int n = sc.nextInt();
		for (int j = 1; j <= n; j++) {
			System.out.printf("您购买的号码为:");
			for (int i = 1; i <= 7; i++) {
				int number = (int) (Math.random() * 10);
				System.out.print(number);
			}
			System.out.println();
		}
		}else{
			System.out.println("输入无效!");
		}
	sc.close();
	}
}


<pre name="code" class="java"><pre name="code" class="java">package com.lovo;
import java.util.Scanner;

/**
 * 21根火柴游戏;
 * @author Administrator
 */

public class Game {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = 21;
		while (n > 0) {
			System.out.printf("请输入您想取得根数:");
			int x = sc.nextInt();
			if (x > 4 || x <= 0 || x > n) {
				System.out.printf("输入有误!仅限于1-4之间的根数\n");
				continue;
			}
			System.out.println("您取了" + x + "根");
			if (n - x == 0) {
				System.out.println("你输了!");
				break;
			} else {
				System.out.println("电脑取了" + (5 - x) + "还剩余" + (n - 5));
				n -= 5;
			}
		}
		sc.close();
	}
}

package com.lovo;
/**
 * 完美数
 * @author 周博
 *
 */

public class Number {
	public static void main(String[] args) {
		for (int i = 1; i <= 10000; i++) {
			int sum = 0;
			for (int j = 1; j < i; j++) {
				if (i % j == 0) {
					sum += j;
				}
			}
			if (sum == i) {
				System.out.println(i);
			}
		}
	}
}

package com.lovo;
import java.util.Scanner;
/**
 * 赌博游戏
 * @author 周博
 */

public class Craps {
	public static int roll() {
		return (int) (Math.random() * 6 + 1);
	}
	public static void main(String[] args) {
		int firstPoint, currentPoint;
		int money = 5000; 
		Scanner sc = new Scanner(System.in);
		for (;;) {
			System.out.printf("请下注:");
			int c = sc.nextInt();
			if (c > money) {
				System.out.print("筹码不足!目前拥有筹码:" + money + "\n");
				continue; 
			}
			firstPoint = currentPoint = roll() + roll();
			System.out.println("玩家摇出了" + currentPoint + "点");
			boolean goon = false;
			switch (currentPoint) {
			case 7:
			case 11:
				System.out.println("玩家胜!");
				money += c;
				System.out.println("拥有筹码:" + money);
				break;
			case 2:
			case 3:
			case 12:
				System.out.println("庄家赢!");
				money -= c;
				System.out.println("剩余:" + money);
				break;
			default:
				goon = true;
			}
			while (goon) {
				currentPoint = roll() + roll();
				System.out.println("玩家摇出了" + currentPoint + "点");
				if (currentPoint == 7) {
					System.out.println("庄家胜!");
					money -= c;
					System.out.println("剩余:" + money);
					goon = false;
				} else if (currentPoint == firstPoint) {
					System.out.println("玩家胜!");
					money += c;
					System.out.println("剩余:" + money);
					goon = false;
				}
			}
			if (money == 0) {
				System.out.println("GAME OVER!");
				break; 
			}
		}
		sc.close();
	}
}


 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值