题目内容

设计一个简单的猜数游戏:随机产生一个1~100之间的数,要求将输入的数与随机产生的数进行比较,如果输入的数比随机数大,则提示“你猜大了”,如果输入的数小了,则提示:“你猜小了” ,如果一样则提示“猜对了!” ,则终止游戏。如果猜不对,游戏一直进行,直到猜对。public class GuessNum {public static void main(String[] args) {Scanner sc=new Scanner(1);Random rnd=new Random();int rndNum=2;while(true){System.out.print("请输入你猜的数:");int num=3 ;if(4 ){System.out.println("你猜大了");}else if(5 ){System.out.println("你猜小了");}else{System.out.println("你猜对了");6 ;}}}}

查看答案
更多问题

打印2-1000之间的所有素数,每行显示8个素数。统计一共有多少个素数。public class PrimeNumber {public static void main(String[] args) {int 1;for (int num = 2; num <= 1000; num++) {int j;for (2; j < num; j++) {if (num % j == 0) {3 ;}}if ( 4 ) {count++;System.out.print(num + "\t");if(5 ){System.out.println();}}}System.out.println("一共有"+count+"个质数");}}

百钱买百鸡问题:公鸡每只值5 文钱,母鸡每只值3 文钱,而3 只小鸡值1 文钱。现在用100 文钱买100 只鸡,问:这100 只鸡中,公鸡、母鸡和小鸡各有多少只?public class Chicken {public static void main(String[] args) {for (int x = 0; x <= 100 / 5; x++) {for (int y = 0; y <= 100 / 3; y++) {int z =2;if (5 * x + 3 * y + z / 3 == 100 && 2) {System.out.println("公鸡有:" + x + " 母鸡有:" + y + " 小鸡有:" + z);}}}}}

一元钱换为1、2、5分的硬币,有多少种兑换方法。public class ChangeMoney {public static void main(String[] args) {int 1 ;for(int five=0;five<=20;five++){for(int two=0;two<=50;two++){int one=2-3-2*two ;if(one>=0){count++;}}}System.out.println("一共有"+count+"种兑换方法");}}

一元钱换为1、2、5分的硬币,有多少种兑换方法。public class ChangeMoney {public static void main(String[] args) {int count=0;for(int five=0;five<=20;five++){for(int two=0;1;two++){int one=100-5*five-2*two;if(2){3 ;}}}System.out.println("一共有"+count+"种兑换方法");}}

答案查题题库