Java 1019,
分享于 点击 27968 次 点评:178
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();
}
}
相关文章
- 暂无相关文章
用户点评