package com.love;
public class Test02 {
public static double jc(int n){
double jc = 1;
for (int j = 1; j <= n; j++){
jc = jc * j;
}
return jc;
}
/**
* 100内的素数
* @author 文波
*
*
*/
public static boolean isPrime(int n){
for (int j =2; j <= Math.sqrt(n); j++){
if (n % j == 0){
return false;
}
}
return true;
}
public static void main(String[] args) {
System.out.println("素数有:");
for (int i = 1; i <= 100; i++){
if(isPrime(i) ){
System.out.printf("%d ", i);
}
}
}
package com.love;
import java.util.Scanner;
public class Test04 {
public static int gongyue(int x, int y){
int temp;
if (x > y){
temp = x;
x = y;
y = temp;
}
for (int i = x; i > 1; i--){
if (x % i == 0 && y % i == 0){
return i;
}
}
return 1;
}
public static int gongbei(int x, int y){
return x * y / gongyue(x, y);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("输入第一个数:");
int n = sc.nextInt();
System.out.print("输入第二个数:");
int m = sc.nextInt();
System.out.println(n + "和 "+ m +"的最大公约数是:" + gongyue(n, m));
System.out.println(n + "和 "+ m +"的最大公倍数是:" + gongbei(n, m));
sc.close();
}
}
package com.love; import java.util.Scanner; /** * 七星彩选号 * @author文波 * */ public class Test05 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("请输入组数:"); int n = sc.nextInt(); for (int i = 1; i <= n; i++){ int num; for (int j = 1; j <= 7; j++){ num = (int)(Math.random()*11 -1); if (j == 7){ System.out.println(); } System.out.print(num); } } sc.close(); } }
package com.love;
import java.util.Scanner;
/**
* 猜数字
* @author 文波
*/
public class Test06 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, count = 0;
int m = (int)(Math.random() * 100);
do{
count++;
System.out.print("请输入数字:");
n = sc.nextInt();
if (n == m){
System.out.println("恭喜你,猜对了!");
System.out.println("你共猜了!" + count + "次");
}
else if (n > m){
System.out.println("亲,小一点!");
}
else{
System.out.println("亲,大一点!");
}
}while (n != m);
}
}
package com.love;
/**
* Craps赌博游戏
* @author 文波
*
*/
public class Test08 {
public static int roll(){
return (int) (Math.random() * 6 + 1);
}
public static void main(String[] args) {
int firstPoint, currentPoint;
firstPoint = 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 (firstPoint == currentPoint){
System.out.println("玩家胜");
break;
}
}
}
}
原文:http://www.cnblogs.com/Barneyman/p/4035246.html