Java 循环运算试题1

来源:互联网 发布:suse linux 安装gcc 编辑:程序博客网 时间:2024/05/29 15:44
package src;// 百鸡百钱问题:public class Java2 {public static void main(String[] args) {for(int x = 0; x <= 20; x++){for(int y = 0; y <= 33; y++){int r = 100 -x -y;if (5 * x + 3 * y + r / 3 == 100 && r % 3 == 0){System.out.printf("公鸡%d\n母鸡%d\n小鸡%d\n\n" , x, y, r );}}}}}



  1. package src;import java.util.Scanner;public class Test3 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("请输入你想下注的数:");if(sc.hasNext()){int n = sc.nextInt();if (n > 0){for(int j = 1; j <= n; j++){for(int i = 1; i <= 7; i++);{System.out.print((int) (Math.random() * 10) + " ");}System.out.println();}}}sc.close();}}

    }
    package src;import java.util.Scanner;/** *  * Craps赌博游戏 * @author 张小龙 * */public class Test5 {public static int roll(){return (int) (Math.random() * 6 + 1);}public static void main(String[] args) { Scanner sc = new Scanner(System.in);int  money = 10000;int firstpoint, currentpoint;for( ; money > 0 ;){firstpoint = currentpoint = roll() + roll();System.out.println("现在有 "  + money + "" );boolean goon = false;System.out.println("请下注: ");     int n = sc.nextInt();     System.out.println("玩家摇出了"+ currentpoint + "点");switch(currentpoint) {case 7:case 11:System.out.println("玩家胜!!!");money += n ;break;case 2:case 3:case 12:System.out.println("庄家胜!!!");money -= n;break;default:goon = true;}while (goon){currentpoint = roll() + roll();System.out.println("玩家摇出了" + currentpoint + "点");if(currentpoint == 7){System.out.println("庄家胜");money -= n;goon = false;}else if(currentpoint == firstpoint){System.out.println("玩家胜");money += n;goon = false;   }}if(money  == 0){System.out.println("你输完了!!!");}}}}

0 0