码迷,mamicode.com
首页 > 其他好文 > 详细

day1019

时间:2014-10-19 19:55:16      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   java   for   sp   div   

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;
			}
		}
		
		
	}

}

  

day1019

标签:style   blog   color   os   ar   java   for   sp   div   

原文地址:http://www.cnblogs.com/Barneyman/p/4035246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!